Answer the question
In order to leave comments, you need to log in
How to display posts using AJAX WordPress?
When a user on the site has already clicked on a post on the News page, the post itself opens, I need to do this: the user scrolls to the end of the post, after which the next post on the same page is loaded. So far, what I have done is sending a request to the server using ajax (that is, there is a working handler in function.php). Tell me how can I get the next post on the server side?
I know there is a get_next_post() function, but it doesn't work in function.php because the $post global variable is empty and the method doesn't seem to have a reason to start from.
Increasing the ID by 1 is also not an option, since there are various topics on the site and, for example, posts with the news tag are clearly out of order, in terms of 1, 2, 3, 4...
The only idea that comes to my mind is: send the current ID and category to the handler, then make a request through WP_Query on the category, after getting the result through the loop and the condition, get the next post based on the ID.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question