Title: Sort Posts on a Custom Field&#8217;s Value?
Last modified: November 10, 2017

---

# Sort Posts on a Custom Field’s Value?

 *  Resolved [mpedersen](https://wordpress.org/support/users/mpedersen/)
 * (@mpedersen)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/sort-posts-on-a-custom-fields-value/)
 * What a great plugin…worked effortlessly. And in doing so, revealed a shortfall
   of the content I’m trying to sort.
 * The shortcode as set for the page I linked: [a-z-listing post-type=”post” taxonomy
   =”category” terms=”restaurant-reviews”]
 * In short, it’s using the Post’s Title and sorting on that. But what I’d like 
   to do is use a post’s custom-field ‘Restuarant’ and sort-on and display that 
   value.
 * It it possible with this plugin? Thanks a bunch – again, super easy, slick, nice
   job!
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fsort-posts-on-a-custom-fields-value%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [Dani Llewellyn](https://wordpress.org/support/users/diddledani/)
 * (@diddledani)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/sort-posts-on-a-custom-fields-value/#post-9725450)
 * Hi,
 * You can override the index letter for each post by hooking the `a_z_listing_item_indices`
   filter.
 *     ```
       function override_the_a_z_index_letter( $indices, $item ) {
           if ( 'expected_post_type' !== $item->post_type ) {
               return $indices;
           }
           $meta = get_post_meta( $item->ID, 'your_meta_key', true );
           $idx = mb_substr( $meta, 0, 1, 'UTF-8' );
           // replace the current indices - if you just want to add it as an additional index
           // add the value to a new item in $indices rather than overwriting $indices entirely
           $indices = array(
               $idx => array(
                   array(
                       'title' => $item->post_title,
                       // or use the value in $meta - this is shown as the post title in the listing
                       'item' => $item,
                   ),
               ),
           );
           // I really need to improve this so you don't need to add all that boiler plate
           // but instead just return the indices. For the future.
           return $indices;
       }
       add_filter( 'a_z_listing_item_indices', 'override_the_a_z_index_letter', 10, 2 );
       ```
   
 * **References:**
    - [https://developer.wordpress.org/reference/functions/add_filter/](https://developer.wordpress.org/reference/functions/add_filter/)
    - [https://developer.wordpress.org/reference/functions/get_post_meta/](https://developer.wordpress.org/reference/functions/get_post_meta/)
    -  [https://secure.php.net/manual/en/function.mb-substr.php](https://secure.php.net/manual/en/function.mb-substr.php)
    - [https://a-z-listing.com/reference/hooks/a_z_listing_item_indices/](https://a-z-listing.com/reference/hooks/a_z_listing_item_indices/)
 *  -  This reply was modified 8 years, 6 months ago by [Dani Llewellyn](https://wordpress.org/support/users/diddledani/).
      Reason: fix the array

Viewing 1 replies (of 1 total)

The topic ‘Sort Posts on a Custom Field’s Value?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/a-z-listing_d8edfd.svg)
 * [A-Z Listing](https://wordpress.org/plugins/a-z-listing/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/a-z-listing/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/a-z-listing/)
 * [Active Topics](https://wordpress.org/support/plugin/a-z-listing/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/a-z-listing/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/a-z-listing/reviews/)

## Tags

 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)
 * [sorting](https://wordpress.org/support/topic-tag/sorting/)

 * 1 reply
 * 2 participants
 * Last reply from: [Dani Llewellyn](https://wordpress.org/support/users/diddledani/)
 * Last activity: [8 years, 6 months ago](https://wordpress.org/support/topic/sort-posts-on-a-custom-fields-value/#post-9725450)
 * Status: resolved