I don’t know why you would see WP_Query
arguments in the data returned, a copy/paste of your code here (with a few adjustments- post type, taxonomy, and term name) does not produce that result.
Getting the post excerpt via get_post_field
will only work if you explicitly entered an excerpt in that field, it will not generate one from post_content
. You’ve also not defined $post_id
, but that shouldn’t matter as it will fall back to the current $post
.
Here’s a version with the unnecessary bits removed, and some slight adjustments:
function my_ajax_pagination() {
$name = $_POST['termname'];
$args = array(
'post_type' => 'myposttype',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'mytaxonomyname',
'field' => 'slug',
'terms' => $name
)
)
);
$posts = new WP_Query( $args );
if( ! $posts->have_posts() ) {
echo "I don't work yet";
}
else {
while ( $posts->have_posts() ) {
$posts->the_post();
echo get_the_excerpt();
}
}
die();
}
One other change I would suggest is to put your post data into an array and return it via wp_send_json
rather than echo data and markup directly.