Created
May 9, 2016 05:58
-
-
Save devudit/93aaaad90e6d28f3d6c4eb7b2717492c to your computer and use it in GitHub Desktop.
How to change sort order of post page navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// get_posts in same custom taxonomy | |
$postlist_args = array( | |
'posts_per_page' => -1, | |
'orderby' => 'menu_order title', | |
'order' => 'ASC', | |
'post_type' => 'your_custom_post_type', | |
'your_custom_taxonomy' => 'your_custom_taxonomy_term' | |
); | |
$postlist = get_posts( $postlist_args ); | |
// get ids of posts retrieved from get_posts | |
$ids = array(); | |
foreach ($postlist as $thepost) { | |
$ids[] = $thepost->ID; | |
} | |
// get and echo previous and next post in the same taxonomy | |
$thisindex = array_search($post->ID, $ids); | |
$previd = $ids[$thisindex-1]; | |
$nextid = $ids[$thisindex+1]; | |
if ( !empty($previd) ) { | |
echo '<a rel="prev" href="' . get_permalink($previd). '">previous</a>'; | |
} | |
if ( !empty($nextid) ) { | |
echo '<a rel="next" href="' . get_permalink($nextid). '">next</a>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment