我的functions.php文件中有以下内容。我试图为自定义帖子返回元值。
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
}
当我使用不同的查询并将$ post_id和$ meta_key_value的值硬编码到其中时...我按预期得到了我的结果。出于某种原因,上面的查询将不接受我的变量!有人可以帮忙吗?