【发布时间】:2014-07-17 20:20:18
【问题描述】:
我无法弄清楚如何对我的自定义帖子类型进行排序,有 2 个分类法。
分类法 1) 位置(即纽约多伦多)- slug:位置 分类法 2) 贸易(即木匠、电工) - 蛞蝓:贸易
查看多伦多页面时(使用我的分类模板:taxonomy-location.php),我希望能够对多伦多列出的所有交易进行排序。它应该看起来像这样:
——
多伦多(页面标题)
木匠
木匠 1 姓名,木匠 2 姓名,木匠 3 姓名,木匠 4 姓名
电工
电工 1 姓名、电工 2 姓名、电工 3 姓名、电工 4 姓名
——
我正在我的自定义分类模板 (taxonomy-location.php) 中创建查询循环,因此我假设显示的帖子已经在多伦多位置进行了标记,但情况似乎并非如此.
这是我的 taxonomy-location.php 文件中的循环:
<?php
$args=array(
‘trade’ => ‘carpenters’,
'post_type' => 'post_type_name',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'Carpenters';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
如果我在第一个数组中添加位置分类的另一个参数,它可以工作——但我不希望它仅限于多伦多。我希望它从您正在查看的任何位置页面(即纽约、多伦多等)中提取。
<?php
$args=array(
‘trade’ => ‘carpenters’,
'location' => ‘toronto’, // this should be something like this <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?>
'post_type' => 'post_type_name',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'Carpenters';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
最好的方法是什么?
【问题讨论】:
标签: php wordpress custom-post-type taxonomy