I have the following in my functions.php file. I’m trying to return a metavalue(s) for a custom post.
add_action( 'transition_post_status', 'a_new_post', 10, 3 );
function a_new_post( $new_status, $old_status, $post ) {
if ( 'publish' !== $new_status or 'publish' === $old_status )
return;
if ( 'post' == $post->jobman_job )
return; // all of the above is just to trigger the below when my custom post is published
global $wpdb;
$post_id = $post->ID;
$meta_key_value = 'data19';
$table_name = $wpdb->prefix . 'postmeta';
$result = $wpdb->get_results("SELECT meta_value FROM " . $table_name . " WHERE post_id = %d AND meta_key = %s", $post_id, $meta_key_value);
var_dump ($result); // I'm getting NULL
}
When I use a different query and hardcode the values for $post_id and $meta_key_value into it… I get my result as expected. For some reason, the above query will not accept my variables! Can anybody assist?