WP post meta isn’t called in ajax
Question
Is there a function that resolve the problem to show bool(false) when I call get_post_meta using Ajax. Bool(false) display with a var_dump Otherwise I have nothing.
I get this problem only with ajax. With my single.php the get_post_meta is displayed.
I don’t have error, only “bool(false)”.
Do you know where the problem comes from ?
Here is my code:
function more_content() {
$the_post_id = $_POST['the_ID'];
$args = array(
'post_type' => 'post',
'p' => $the_post_id
);
$ajax_query = new WP_Query($args);
if ( $ajax_query->have_posts() ) : while ( $ajax_query->have_posts() ) :
$ajax_query->the_post();
$meta_video1 = get_post_meta($post->ID, 'video1', true);
$meta_video2 = get_post_meta($post->ID, 'video2', true);
$meta_video3 = get_post_meta($post->ID, 'video3', true);
$meta_image1 = get_post_meta($post->ID, 'image1', true);
$meta_image2 = get_post_meta($post->ID, 'image2', true);
$meta_image3 = get_post_meta($post->ID, 'image3', true);
if ( metadata_exists( 'post', $post->ID , 'video1' ) ){ echo $s_cv . $meta_video1 . $e_c ; }
if ( metadata_exists( 'post', $post->ID , 'video2' ) ){ echo $s_cv . $meta_video2 . $e_c ; }
if ( metadata_exists( 'post', $post->ID , 'video3' ) ){ echo $s_cv . $meta_video3 . $e_c ; }
if ( metadata_exists( 'post', $post->ID , 'image1' ) ){ echo $s_ci . $s_src . $meta_image1 . $e_src . $e_c;}
if ( metadata_exists( 'post', $post->ID, 'image2' ) ){ echo $s_ci . $s_src . $meta_image2 . $e_src . $e_c;}
if ( metadata_exists( 'post', $post->ID , 'image3' ) ){ echo $s_ci . $s_src . $meta_image3 . $e_src . $e_c;}
And the ajax call :
jQuery(document).ready(function(){
jQuery('.post-link').click(function() {
var post_id = jQuery(this).attr("id");
jQuery.post(
ajaxurl,
{
'action': 'more_content',
'the_ID': post_id
},
function(response){
jQuery('#more-content').html(response);
}
);
return false;
});});
0
ajax, post-meta
4 years
2020-03-23T12:51:51-05:00
2020-03-23T12:51:51-05:00 0 Answers
106 views
0
Leave an answer