Forked from banago/infinite-previous-next-looping.php
Last active
May 12, 2016 17:18
-
-
Save accrane/8728f15a4c8cdf734c4aa3a35e6aa960 to your computer and use it in GitHub Desktop.
Infinite next and previous post looping but in same term in WordPress
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 | |
/** | |
* Infinite next and previous post looping in WordPress | |
* | |
* This will stay in same Custom Taxonomy Term. Also NEXT and PREVIOUS | |
* are switched to give the impression of "Going Forard and Back" | |
*/ | |
if( get_adjacent_post(true, '', false, 'CUSTOM_TAX') ) { | |
next_post_link( '%link', 'PREVIOUS', TRUE, ' ', 'CUSTOM_TAX' ); | |
} else { | |
$args = array( | |
'post_type'=>'CUSTOM_POST_TYPE', | |
'posts_per_page' => 1, | |
'order' => 'ASC', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'CUSTOM_TAX', // your custom taxonomy | |
'field' => 'slug', | |
'terms' => array( 'term' ) // the terms (categories) you created | |
) | |
) | |
); | |
$first = new WP_Query($args); | |
$first->the_post(); | |
echo '<a href="' . get_permalink() . '">PREVIOUS</a>'; | |
wp_reset_query(); | |
}; | |
if( get_adjacent_post(true, '', true, 'CUSTOM_TAX') ) { | |
previous_post_link( '%link', 'NEXT', TRUE, ' ', 'CUSTOM_TAX' ); | |
} else { | |
$args = array( | |
'post_type'=>'CUSTOM_POST_TYPE', | |
'posts_per_page' => 1, | |
'order' => 'DESC', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'CUSTOM_TAX', // your custom taxonomy | |
'field' => 'slug', | |
'terms' => array( 'term' ) // the terms (categories) you created | |
) | |
) | |
); | |
$first = new WP_Query($args); | |
$first->the_post(); | |
echo '<a href="' . get_permalink() . '">NEXT</a>'; | |
wp_reset_query(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment