unique post in “$args” of wp_query display more than one post

I can’t find the rights arguments to display only one post of a category when I click on a div. I call the post with Ajax and I display it in a div popup.Perhaps these arguments are not sufficient, or the problem come from another part?But when I echo the get_the_id in the loop it is the correct id of the post.However, it displays all posts in category. Another problem, if I don’t specify a category (name or id) it display all posts of my WordPress.These two problems come only when I call posts in Ajax.

function more_content() {

$the_post_id = the_ID(); // $_POST[‘the_ID’];
$args = array(
‘post_type’ => ‘post’,
‘category_name’ => ‘materials’,
‘p’ => $the_post_id

);

$ajax_query = new WP_Query($args);
$the_excerpt;
$the_content;

if ( $ajax_query->have_posts() ) : while ( $ajax_query->have_posts() ) : $ajax_query->the_post();

$the_excerpt = the_excerpt();
$the_content = the_content();

endwhile;
endif;
echo $the_excerpt;
echo “<div style=’color:white; font-size:40px;’>”,$the_post_id,”</div>”;
echo $the_content;

wp_reset_postdata();

die();
}

Read more here:: unique post in “$args” of wp_query display more than one post

Leave a Reply

Your email address will not be published. Required fields are marked *