Next and previous link in custom post type in the same taxonomy term

previous_post_link() and next_post_link() work perfectly with custom post types. You need to paste this code in your single-customposttype.php (which in your case is single-portfolio.php): <div class=”previous-post-link”> <?php previous_post_link(‘%link’, ‘<< Previous Post’, $in_same_term = true, $excluded_terms=””, $taxonomy = ‘the-custom-taxonomy-associated-with-your-custom-post-type’); ?> </div> <div class=”next-post-link”> <?php next_post_link(‘%link’, ‘Next Post >>’, $in_same_term = true, $excluded_terms=””, $taxonomy = ‘the-custom-taxonomy-associated-with-your-custom-post-type’); ?> … Read more

Why is previous_post_link and next_post_link working outside of the Loop?

“Inside the Loop” essentially means that function relies on data from global variables (such as $post) that are set up when Loop runs. Note that this is not necessarily done by main Loop of query_posts(). In your specific code those variables are filled by $custom_posts->the_post() calls and after that wp_reset_query() gets those values back to … Read more

Filter get_adjacent_post() for private posts, how to modify JOIN/WHERE?

First of all I suggest you to use a function to return the terms to exclude, that will help you to get them in different places without having to repeat code, e.g. in the ‘pre_get_posts’ filter and the adjacent post filters. So: function get_level_term_to_exclude() { if ( current_user_can (‘manage_options’) || current_user_can (‘view_level1_posts’) ) { return … Read more

How to get next and previous post links, alphabetically by title, across post types, in a shortcode

So in order to do this, I had to filter the SQL queries. I found this snippet that filters post order by title and returns them for next and previous post links. Unfortunately, this doesn’t work in a custom post type. So I replaced ‘post’ with get_post_type($post) to grab the current post type and return … Read more