我想显示所有代理a-z,除了有一个代理应该总是最后出现。理想情况下,我希望从自定义字段dName的值进行排序。
我环顾四周,似乎meta\\u查询是实现这一点的最佳新方法,但尚未找到答案。
显示最近创建的10个代理的当前代码。
<?php $loop = new WP_Query( array( \'post_type\' => \'agents\', \'posts_per_page\' => 10 ) ); ?>
感谢您的关注。编辑2011年3月27日,工作代码
<?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.\';
}
?>