Answer the question
In order to leave comments, you need to log in
Print page id starting from next id after current page id?
There is a site on Wordpress, it has a block Similar pages, which displays the id of similar pages from the Categories section, you need to go through all the pages of this section.
You need to display the id of the next 5 pages that come after the current page, for example, for a page with post id 12, the next page id will be, for example, 13, 15, 16, 20, 25.
For a page with post id 13, id will be 15, 16 , 20, 25, 26.
Moreover, if at some step there is no ID greater than the current one, then you need to take the smallest ID - so that everything is looped, i.e. you need to make an automatic circular linking of pages.
The page with id 100 in the Similar pages block should have links starting from a lower id, for example, from id 12.
Now there is a function in the code, but it displays only one id of the next page, and you need 5 id of the next pages. How to do it in a loop for different pages?
function get_next_post_id($post_id) {
// Get a global post reference since get_adjacent_post() references it
global $post;
// Store the existing post object for later so we don't lose it
$oldGlobal = $post;
// Get the post object for the specified post and place it in the global variable
$post = get_post($post_id);
// Get the post object for the next post
$next_post = get_next_post();
// Reset our global object
$post = $oldGlobal;
if ('' == $next_post)
return 0;
return $next_post->ID;
}
global $wp_query;
$cur_id = $wp_query->get_queried_object_id();
$next_ID = get_next_post_id($cur_id);
echo "<a href=\"" . esc_url(get_permalink()) . "\">" . $next_ID . "</a> ";
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