Many searches and tests but in vain, I need an expert to rescue me.
I need a custom post query in worpdress, which returns only 5 posts starting from a specific post. In other terms, there is a div in single.php where i need the list of 5 posts starting from the current post (the post returned by single.php)
I hope I was clear thanks for your valuable help.
You can do this by using
get_adjacent_post()
and the filterget_previous_post_where
orget_next_post_where
. You’ll callget_adjacent_post()
as normal, but you’ll need to change theLIMIT
to 5, using the filter.I wasn’t sure from the question whether or not you wanted to have the current post be first. If you do, you’ll need to set the
LIMIT
to 4 and then use the current postdata to generate the first post.I would create an array of post ids, and then use
get_post()
when you iterate through them, as I believe thatget_adjacent_post()
will return raw rows from the database.You have to keep resetting the $post variable to advance the loops post counter.
Use something like this: