Hi I am trying to call a python script when I press update on a wordpress post. This works well but I am noticing that if I just update the metadata of the post, this is not updated. How can I fix it? Is there a method that I can call to save the metadata post as well?
This is my code:
function mysave($id, $post)
{
if ($post->post_type != 'item'){
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
return;
}
if ( (defined( 'REST_REQUEST' ) && REST_REQUEST ) ){
return;
}
if (wp_is_post_revision($id)) {
return;
}
if (wp_is_post_autosave($id)) {
return;
}
if ( 'trash' === $post->post_status ) {
return;
}
if ( 'draft' === $post->post_status ) {
return;
}
$dig = get_post_meta($id, 'wpcf-digitisation-project-no')[0];
#$hmml = get_post_meta($id, 'wpcf-hmml-project-no')[0];
$inv = get_post_meta($id, 'wpcf-inventory-no')[0];
if($dig!=""){
$command = escapeshellcmd('python3 '. dirname(__file__). '/create_pdf.py digital '.$inv);
}else{
$command = escapeshellcmd('python3 '. dirname(__file__). '/create_pdf.py hmml '.$inv);
}
exec( $command, $output, $ret_code);
if($ret_code != 0){
$tmp = fopen(dirname(__file__).'/my_logs.txt', "a+");
fwrite($tmp,"\nFailed to create pdf for record with inventory number: ".get_post_meta($id, 'wpcf-inventory-no')[0]."\n");
fclose($tmp);
}else{
$tmp = fopen(dirname(__file__).'/my_logs.txt', "a+");
fwrite($tmp,"\nPDF successfully created for record with inventory number: ".get_post_meta($id, 'wpcf-inventory-no')[0]."\n");
fclose($tmp);
}
}