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

  1. cw17s0n
    Posted 4 years 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(
                'key' => 'lname'
    $wpse20766q = new WP_Query( $wpse20766args );
    // then the loop...
    if( $wpse20766q->have_posts() ):
    while( $wpse20766q->have_posts() ) :
    // do stuff...
  2. degamer12
    Posted 4 years 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
    Posted 4 years 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
    Posted 4 years 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(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic