Get the index (or position) of a post within a custom post type?
-
Let’s say I have 5 articles within a custom post type named “Games”:
Minecraft, Terraria, Amnesia, Braid, Battlefield
If the user requests the page “Amnesia”, I need to figure out the index of this page (in this example, the index would be 3).
I also need the opposite, if the user requests item #3, I need to send them “Amnesia”.
I am currently using a custom wp_query to start pagination:
$args = array( 'post_type' => 'press', 'posts_per_page' => 5, 'paged' => $paged, 'orderby' => 'date', 'order' => 'DESC', ); $nav_query = new WP_Query( $args );
In the above code, the $paged variable is not set – nor will it ever be set. I need to replace $paged with something like:
floor( $the_page_index / $posts_per_page )
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Get the index (or position) of a post within a custom post type?’ is closed to new replies.