WP_QUERY循环不适用于我自定义分类

时间:2013-06-11 作者:RonandVam

我的循环不显示我所有相关的帖子,它应该显示以特定字母开头的所有帖子(如果是“”,那么它应该显示按人气排序的所有帖子)有什么问题吗?

 $paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
 if ($first_letter!=\' \') { $args = array (
        \'posts_per_page\' => $posts_per_page,
        \'taxonomy\' => $term->taxonomy,
        \'term\' => $term->name,
        \'post_type\' => $post_type,
        \'orderby\' => \'title\',
        \'order\' => \'ASC\',
        \'paged\' => $paged); }
    else {$args = array (
        \'posts_per_page\' => $posts_per_page,
        \'taxonomy\' => $term->taxonomy,
        \'term\' => $term->name,
        \'post_type\' => $post_type,
        \'meta_key\' => \'post_views_count\',
        \'orderby\' => \'meta_value_num\',
        \'showposts\' => 160,
        \'order\' => \'DESC\',
        \'paged\' => $paged); }

 $the_query = new WP_Query( $args );

 $mam_global_where = \'\'; // Turn off filter
 if ( $the_query->have_posts() ) {
    $in_this_row = 0;
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        if ($first_letter!=\' \'&&$first_letter!=\'\') { $first_letter = strtoupper(substr(apply_filters(\'the_title\',$post->post_title),0,1));}
        if ($first_letter != $curr_letter) {
            if (++$post_count > 1) { end_prev_letter(); }
            start_new_letter($first_letter);
            $curr_letter = $first_letter;
            }
        if (++$in_this_row > $posts_per_row) {
            end_prev_row();
            start_new_row();
            ++$in_this_row; // Account for this first post
            } ?>
    <a href="<?php the_permalink(); ?>" rel=.....</a>   
    </div> <!--end #post-->
    <?php }
 end_prev_letter();

1 个回复
SO网友:Milo

你的taxonomyterm 参数不正确。首选方法是通过tax_query

$args = array(
    // ... other args
    \'tax_query\' => array(
        array(
            \'taxonomy\' => $term->taxonomy,
            \'field\' => \'slug\',
            \'terms\' => $term->name
        )
    )
);
请参见WP_Query 用于所有有效参数及其正确格式。

结束

相关推荐

2 loops in blog homepage

I would like to have to query loops running on my blog homepage:Featured posts on top displaying 3 posts from the category : \"Featured\"Underneath it just the basic loop of wordpress which display the latest (10 or other, whatever is selected within the