Here my code for taxonomy industries of Event custom post type:
// 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
),
));
Another taxonomy of Event:
// 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
),
));
And in dashboard admin, i create a new Industries taxonomy: test-indus, here is image of my dashboard admin
I get posts of industrie taxonomy by this code:
$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);
And here is result when i var_dump($queried_object)
I don’t understand why $queried_object->taxonomy return to ‘type-events’?? The truth it should be ‘industries’?
I just a newbie, plz help me, thank so much 🙂