What's a working method to show link to next and previous same custom post type article, ordered by title and not id? (generally applying a filter to the order)

1 Answer 1


If you use a filter like the following to adjust the order of a post type archive, then the next & previous links will work perfectly without need for modification:

function wpse_139866_set_order_by( $wp_query ) {
    if ( ! is_admin() && $wp_query->is_post_type_archive( 'my_post_type' ) && $wp_query->is_main_query() ) {
        $wp_query->set( 'orderby', 'title' );

add_action( 'pre_get_posts', 'wpse_139866_set_order_by' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.