我正在执行Ajax调用并返回值。帖子 ID 即将到来。但是当我尝试使用此代码时,它返回为空白
function visa_status() {
$postid = $_POST['appid'];
// args
$args = array(
'numberposts' => 1,
'post_type' => 'cpt_15',
'meta_key' => 'application_number',
'meta_value' => $postid
);
$metaarry = array();
// query
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$posti = get_the_ID();
endwhile;
//echo $posti;
echo get_post_meta( $posti, 'given_name');
exit();
}
在上面的代码中,$posti即将到来。但是get_post_meta((不起作用。 这是我的JS部分
onStepChanging: function (event, currentIndex, newIndex) {
if ( newIndex === 1 ) {
jQuery('.wizard > .steps ul').addClass('step-2');
appId = jQuery('#appid').val();
jQuery.ajax({
type: 'POST',
dataType: 'json',
url: my_ajax_object.ajax_url,
data: {
'action': 'visa_status',
'appid': appId,
},
success: function (msg) {
console.log(msg);
}
});
} else {
jQuery('.wizard > .steps ul').removeClass('step-2');
}
if ( newIndex === 2 ) {
jQuery('.wizard > .steps ul').addClass('step-3');
} else {
jQuery('.wizard > .steps ul').removeClass('step-3');
}
return true;
},
我有没有犯过什么错误。请帮我解决这个问题。
试试这个
$given_name = get_post_meta( $posti, 'given_name', true );
echo $given_name;
或者试试这个
echo get_post_meta( $posti, 'given_name', true );
在这里检查get_post_meta
函数根据第三个参数返回什么。