WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Show taxonomy page alphabetically by meta rather than default post date.

[Resolved] Show taxonomy page alphabetically by meta rather than default post date.

  • I have my taxonomy-regions.php to show posts depending on the region taxonomy selected. And it works except I want the posts to display alphabetically.

    The code below works to sort the posts, but ends up showing all posts, not just the region I select.

    $wpse20766args = array(
         'orderby'  => 'meta_value',
         'order'    => 'ASC',
         'post_type'    => 'agent',
         'posts_per_page' => -1,
         'meta_query'   => array(
            array(
                'key' => 'lname'
            )
         )
    );
    
    $wpse20766q = new WP_Query( $wpse20766args );
    
    // then the loop...
    if( $wpse20766q->have_posts() ):
    while( $wpse20766q->have_posts() ) :
    $wpse20766q->the_post(); 
    
    // do stuff...
    
    endwhile;
    endif;
Viewing 3 replies - 1 through 3 (of 3 total)
  • Where is the array do you define that only the posts from the selected region may be loaded ? I can’t find the declaration of that in your array.

    I guess that’s part of what I’m trying to figure out, the pages I currently have show all posts of custom post type “agents”, each post shows a region which is a taxonomy, when I click on a region to see all agents in a specified region, using just this code, <?php while ( have_posts() ) : the_post(); ?> it just works, except it orders posts by post date, here there is no specification of what post to show either but it still works.

    For future reference, this is what ended up working.

    global $wp_query;   
    
    query_posts(array_merge(array('orderby' => 'meta_value', 'meta_key' => 'rw_lname' ),$wp_query->query));
    
    <?php while ( have_posts() ) : the_post(); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Show taxonomy page alphabetically by meta rather than default post date.’ is closed to new replies.
Skip to toolbar