I would like to display all agents a-z, except there is one agent who should always show up last. Ideally I'd like the ordering to be done from the value of a custom field, dName.
I was looking around it seemed that meta_query was the new best way to do this but haven't figured it out yet.
Current code that shows 10 last agents created.
<?php $loop = new WP_Query( array( 'post_type' => 'agents', 'posts_per_page' => 10 ) ); ?>
Thanks for looking.
edit 3/27/2011, working code
<?php
$loop = new WP_Query( array(
'post_type' => 'agents',
'orderby' => 'meta_value',
'meta_key' => 'rw_dname',
'order'=>'ASC',
'meta_query' => array(
array( 'key' => 'rw_dName' )
),
'post__not_in' => array( '98' ),
'posts_per_page' => -1 ) );
$loop2 = new WP_Query( array(
'post_type' => 'agents',
'post__in' => array( '98' ) ) );?>
<?php
if($loop->have_posts() || $loop2->have_posts()) {
if($loop->have_posts()) { while($loop->have_posts()) { $loop->the_post();?>
<div class="agentContent">
<div class="agentThumbnail">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}?>
</div>
<div class="agentInfo"> <span class="agentInfoEntry">
<?php
$meta = get_post_meta(get_the_ID(), 'rw_dname', true);
echo $meta; // if you want to show
?>
</span> </div>
</div>
<?php
} //endwhile
}
?>
<?php
if($loop2->have_posts()) { while($loop2->have_posts()) { $loop2->the_post();?>
<div class="agentContent">
<div class="agentThumbnail">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}
?>
</div>
<div class="agentInfo"> <span class="agentInfoEntry">
<?php
$meta = get_post_meta(get_the_ID(), 'rw_dname', true);
echo $meta; // if you want to show
?>
</span> </div>
</div>
<?php
} //endwhile
}
?>
<?php
} else {
echo 'No Agents.';
}
?>