Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

display taxonomy-regions.php alphabetically by meta key WordPress

  • SOLVED

I want to display a page of posts of specific taxonomy ordered alphabetically by meta.
All details below.

I have a page that displays my cpt 'agents' and displays them alphabetically by meta 'rw_lname',

<?php
$loop = new WP_Query( array(
'post_type' => 'agents',
'orderby' => 'meta_value',
'meta_key' => 'rw_lname',
'order'=>'ASC',
'meta_query' => array(array( 'key' => 'rw_lname' )),
'post__not_in' => array( '93' ),
'posts_per_page' => -1 ) );
$loop2 = new WP_Query( array(
'post_type' => 'agents',
'post__in' => array( '93' ) ) );
?>
<?php
if($loop->have_posts() || $loop2->have_posts()) {
if($loop->have_posts()) { while($loop->have_posts()) { $loop->the_post();
?>

Each agent post displays a taxonomy link for the region associated with that post

<?php echo get_the_term_list( $post->ID, 'regions', 'Regions Served: <br /> ', ' ', '' ); ?>

Upon clicking on a region (taxonomy link) you go to taxonomy-regions.php, which displays all cpt 'agents' that are linked to the taxonomy you clicked on.

Standard WP loop, shows all the right posts, but the order is chronological.

<?php while ( have_posts() ) : the_post(); ?>

I need to make a loop that does what this loop shows, but ordered alphabetically, using meta 'rw_lname'.

Thank You

Answers (1)

2011-06-23

Christianto answers:

Hi,

Please try this query code, put it before the loop on your taxonomy-regions.php

global $wp_query;
query_posts(array_merge(array('orderby' => 'meta_value', 'meta_key' => 'rw_lname' ),$wp_query->query));


Chuck Wilson comments:

Amazing, I spent several hours trying to come up with a solution. Thank You


Christianto comments:

You're welcome..

:D