为什么get_queried_object()返回错误的分类法?

时间:2016-01-02 08:42:19

标签: php wordpress

这是我的事件自定义帖子类型的分类行业代码:

 // Add new "Industries" taxonomy to Events
register_taxonomy('industries', 'event', array(
    'hierarchical' => true,
    'labels' => array(
        'name' => _x( 'Industries', 'taxonomy general name', 'sb_theme' ),
        'singular_name' => _x( 'Industries', 'taxonomy singular name', 'my_theme' ),
        'search_items' =>  __( 'Search Industry', 'my_theme' ),
        'all_items' => __( 'All Industries', 'my_theme' ),
        'parent_item' => __( 'Parent Industry', 'my_theme' ),
        'parent_item_colon' => __( 'Parent Industry:', 'my_theme' ),
        'edit_item' => __( 'Edit Industry', 'my_theme' ),
        'update_item' => __( 'Update Industry', 'my_theme' ),
        'add_new_item' => __( 'Add New Industry', 'my_theme' ),
        'new_item_name' => __( 'New Industry', 'my_theme' ),
        'menu_name' => __( 'Industries', 'my_theme' ),
    ),
    // Control the slugs used for this taxonomy
    'rewrite' => array(
        'slug' => 'industries',
        'with_front' => false, 
        'hierarchical' => true 
    ),
));

事件的另一个分类:

// Add new "Type" taxonomy to Events
    register_taxonomy('type-events', 'event', array(
        'hierarchical' => true,
        'labels' => array(
            'name' => _x( 'Types', 'taxonomy general name', 'my_theme' ),
            'singular_name' => _x( 'Types', 'taxonomy singular name', 'my_theme' ),
            'search_items' =>  __( 'Search Type', 'my_theme' ),
            'all_items' => __( 'All Types', 'my_theme' ),
            'parent_item' => __( 'Parent Type', 'my_theme' ),
            'parent_item_colon' => __( 'Parent Type:', 'my_theme' ),
            'edit_item' => __( 'Edit Type', 'my_theme' ),
            'update_item' => __( 'Update Type', 'my_theme' ),
            'add_new_item' => __( 'Add New Type', 'my_theme' ),
            'new_item_name' => __( 'New Type', 'my_theme' ),
            'menu_name' => __( 'Types', 'my_theme' ),
        ),
        // Control the slugs used for this taxonomy
        'rewrite' => array(
            'slug' => 'type-events', 
            'with_front' => false, 
            'hierarchical' => true
        ),
    ));

在仪表板管理员中,我创建了一个新的行业分类:test-indus,这是我的仪表板管理员的图像Industries taxonomy in admin

我通过以下代码获得了行业分类的帖子:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$queried_object = get_queried_object();
$args = array(
        'post_type' => $post_type,
        'showposts' => '12',
        'tax_query' => array(
                   array(
                         'taxonomy' => $queried_object->taxonomy,
                         'terms' => $queried_object->slug,
                         'field' => 'slug'
                        )
                   ),
        'post_status' => 'publish',
        'paged' => $paged,
        );
$loop = get_posts( $args );
var_dump($queried_object);

这是i var_dump($ queried_object)Result var_dump

的结果

我不明白为什么$ queried_object->分类法会回归'类型事件'?事实应该是'行业'?

我只是一个新手,请帮助我,非常感谢:)。

0 个答案:

没有答案