Forums

[resolved] Show taxonomy page alphabetically by meta rather than default post date. (4 posts)

  1. cw17s0n
    Member
    Posted 11 months ago #

    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;
  2. degamer12
    Member
    Posted 11 months ago #

    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.

  3. cw17s0n
    Member
    Posted 11 months ago #

    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.

  4. cw17s0n
    Member
    Posted 11 months ago #

    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(); ?>

Reply

You must log in to post.

About this Topic