Apply custom sorting for Next / Previous site-wide navigation

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPrint this page

A sort will apply to all next / previous side-wide navigation links if the Next / Previous Apply option is turned on. In case this need to apply only when certain conditions are fulfilled .
The follogin filter can be used ‘apto/navigation_sort_apply’

     add_filter('apto/navigation_sort_apply', 'theme_apto_navigation_sort_apply');
    function theme_apto_navigation_sort_apply($current)
        {
            global $post;
            
            if($post->post_type == 'post')
                $current    =   TRUE;
                else
                $current    =   FALSE;
            
            return $current;   
        }

The above will makes the code to apply the customized sort on navigation links only if post type is a Post.

*This replaced the old cpto/navigation_sort_apply


Subscribe
Notify of
guest
13 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Katrin Gutiérrez

But where do I have to insert this code?

nspcode

You should include this code within your theme functions.php

Note: Just updated the above filter / code as being outdated, please check it again. Also make sure you use the latest plugin version which include a global option for such navigation within Settings > Post Types Order. Use this filter to punctually disable or enable navigation for a certain list

themilossh

Hello,
I’ve just tried it for post_type=”avada_portfolio” and it doesn’t work for me, unfortunately, while the plugin works for portfolio items on frontend. That said, how can I debug it?

nspcode

Hi,
Can you get in touch with us through contact and we’ll check it out for you.

Thanks

themilossh

Sorry, i forgot to mention I’m using free version. Also, links work as expected, but custom ordering isn’t applied on the whole post list, and when I try to get next post, ie get_next_post, custom ordering is not respected

nspcode

Can you check the Settings > Post Types Order > Next / Previous Apply -> make sure this option is checked.

themilossh

Yeah, I’ve checked, and it is indeed checked. The thing is, again, that it applies sort order to the navigation links only.

Chris Flores

Is there a way to have this in a reverse order? It’s showing up my posts backwards

nspcode

The easiest way would be to switch the next / previous links text.

Chris Flores

Sorry if it wasn’t clear. The very first post that I have on the re-order screen seems to be the last post on the single post pages so it doesn’t show any ‘next’ buttons but only shows ‘previous’ instead of it being the first post and showing ‘next’. Any solutions? The code works great it’s just backwards.

nspcode

There must be a filter either within a custom plugin or your theme which change the order from Ascending to Descending. Can you check on that? If you use automatic order, please make sure there’s set for ASC

Regarding the “next” and previous”, the sort list should output in the same order as you see in manual order e.g. the first object would appear first on front side. So, the same as default WordPress output works. Giving the above, for the first item in the lest, there will be no “next” but “previous”. As per codex description, next means a post created after the date of current object. Since per sort list an object is on top, there will be no “next”. The same for the last item in the list, there will be “next” but no “previous”

Lola Li

Hi, I’m having the same issue where the order of the posts is showing correctly but I want the prev/next links to be reversed. e.g. on the first post there is only a Prev link to the following post but instead I want but I want this to be a Next link?

I am using the Rebalance theme, in content-single.php if I switch the strings for ‘prev_text’ and ‘next_text’, it displays the following post as ‘Next’ but the order also switches, so the Next link ends up on left, and Previous is on the right.

the_post_navigation( array(

‘prev_text’ => ” . esc_html__( ‘Next’, ‘rebalance’ ) . ”,
‘next_text’ => ” . esc_html__( ‘Previous’, ‘rebalance’ ) . ”
));

In plugin settings, Auto Sort is unchecked and Next / Previous Apply is checked.

Lola Li

Hi, did you find a solution to this?