S
S
Sergey2018-10-07 12:08:01
WordPress
Sergey, 2018-10-07 12:08:01

Ajax loading posts in custom WP theme?

Good afternoon, tell me how you can load new posts in place of old ones (when clicking on pagination links)? I output some posts in a cycle

$current_page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
  'posts_per_page' => 2,
  'cat'            => 2,
  'offset' 	   => 0,
  'order'          => 'ASC',
  'paged'          => $current_page
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) {
  $query->the_post();
  $good = get_field('good');
  foreach ($good as $item) {
    ?>
      <!-- Здесь выводится товар -->
    <?
  }
}
wp_reset_postdata(); // сброс
?>

And by clicking on the link, I want to make a similar ajax request only by changing the parameter offsetand HTML'итьits in the block where the goods should be (I didn’t come up with a better option :-( )
I understand that I need to make ajaxa request to the file admin-ajax.phpand so that it generates a new set of goods for me and returned it as an answer to jsthe ajax request function, but I don’t understand how to make this php function... can someone give a link or suggest an idea
?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2018-10-07
@1Sergey1

Didn't get the point. You just need to chew ajax how to create in wp? Well, here is a link to kama , there is nowhere to tell in more detail how ajax requests are created in wp. Or was the issue something else?

A
Alexander Sobolev, 2018-10-07
@san_jorich

Create a layer with an id like ajax_result. Assign success to ajax_result. Regarding the creation, see the link to kama

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question