Disable “previous link” in first post and “next link” in last post
<?php next_post_link(‘format’, ‘link’, ‘in_same_cat’, ‘excluded_categories’); ?> <?php previous_post_link($format, $link, $in_same_cat = false, $excluded_categories=””); ?>
<?php next_post_link(‘format’, ‘link’, ‘in_same_cat’, ‘excluded_categories’); ?> <?php previous_post_link($format, $link, $in_same_cat = false, $excluded_categories=””); ?>
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
“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
To get next/prev posts, usually all you need is to se to true the parameter that indicates that next/prev post should be in the same taxonomy term in the get next/prev post functions, you don’t need to deal with any filter. For example: To get next and prev post objects: // First parameter for these … Read more
Update: OK. If you get to keep changing the question, I get to delete what I had written before and start all over again. To be honest, I’m a bit confused about what you are trying to do. Since this appears to be for a single post (based on the comment at the top of … Read more
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
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