Title: Sorting the posts
Last modified: August 20, 2020

---

# Sorting the posts

 *  [imagin8tor](https://wordpress.org/support/users/imagin8tor/)
 * (@imagin8tor)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/sorting-the-posts-2/)
 * there’ some example code in the link supplied that will restrict post navigation
   to the prevailing post category.
 * Anyone know how to SORT the post results by post name or title?
    code below _________
 * add_filter( ‘get_next_post_join’, ‘navigate_in_same_taxonomy_join’, 20);
    add_filter(‘
   get_previous_post_join’, ‘navigate_in_same_taxonomy_join’, 20 ); function navigate_in_same_taxonomy_join(){
   global $wpdb; return ” INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.
   object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id”;}
 * add_filter( ‘get_next_post_where’ , ‘navigate_in_same_taxonomy_where’ );
    add_filter(‘
   get_previous_post_where’ , ‘navigate_in_same_taxonomy_where’ ); function navigate_in_same_taxonomy_where(
   $original ) { global $wpdb, $post; $where = ”; $taxonomy = ‘category’; $op = (‘
   get_previous_post_where’ == current_filter()) ? ‘<‘ : ‘>’; $where = $wpdb->prepare(“
   AND tt.taxonomy = %s”, $taxonomy ); if ( ! is_object_in_taxonomy( $post->post_type,
   $taxonomy ) ) return $original ;
 *  $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( ‘fields’ => ‘
   ids’ ) );
 *  $term_array = array_map( ‘intval’, $term_array );
 *  if ( ! $term_array || is_wp_error( $term_array ) )
    return $original ;
 *  $where = ” AND tt.term_id IN (” . implode( ‘,’, $term_array ) . “)”;
    return
   $wpdb->prepare( “WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status
   = ‘publish’ $where”, $post->post_date, $post->post_type ); }
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fsorting-the-posts-2%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/sorting-the-posts-2/#post-13288387)
 * Hi [@imagin8tor](https://wordpress.org/support/users/imagin8tor/),
 * It looks like the code you’ve provided is specific to the theme you’re using.
   You’ll need to contact the theme author for further questions, as I’m not familiar
   with it.

Viewing 1 replies (of 1 total)

The topic ‘Sorting the posts’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

## Tags

 * [post](https://wordpress.org/support/topic-tag/post/)

 * 1 reply
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [5 years, 9 months ago](https://wordpress.org/support/topic/sorting-the-posts-2/#post-13288387)
 * Status: not a support question