0

我正在尝试使用自定义帖子类型和分类来获取帖子。我尝试使用以下代码:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$args = array(
   'post_type' => 'specification',
   'tax_query' => array(
        array(
'           taxonomy' => 'model',
            'field' => 'slug',
            'term' => 'grand-cherokee-2013'
        )
    ),
    'order' => 'ASC',
    'paged' => $paged
);
$wp_query = new WP_Query( $args );

和:

global $wp_query;
query_posts( array(  
    'post_type' => 'specification',
    'category_name' => 'model',
    'showposts' => '10' ) 
);

我做了 print_r($wp_query),请求是:

SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  WHERE 1=1  AND 0 = 1 AND wp_posts.post_type = 'specification' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10

为什么 wordpress 加 0 = 1?我认为问题就在这里。我该如何解决?

4

2 回答 2

0

I would try this:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$args = array(
   'tax_query' => array(
        array(
'           taxonomy' => 'specification',
            'field' => 'slug',
            'term' => 'grand-cherokee-2013'
        )
    ),
    'order' => 'ASC',
    'paged' => $paged
);
$wp_query = new WP_Query( $args );

I think the problem is that you're setting the taxonomy to 'model' when what you want is 'specification' type.

于 2013-07-18T10:14:42.293 回答
0

你可以试试这个方法

$caledar_custom_detail=get_term($c, 'calendar_category' ); // $c 用于类别 id 和自定义类别类型

$current_slug = $caledar_custom_detail->slug;
$post_query_loop_value=query_posts( array( 'calendar_category' => $current_slug, 'showposts' => 3 ) );

首先在数组中,参数 'calendor_category' 表示自定义类别类型 $current_slug 表示
您要显示多少帖子的类别 slug 'showposts'。

如果没有得到想要的输出,请告诉我。

于 2013-07-18T09:51:17.273 回答