get_quiried_object on my custom post type is not showing my post taxonomy names
I’m on WordPress 6.0. Running PHP 7.4. I have 3 registered taxonomies associated to a custom post type. Below is an example of how one of my registered taxonomies looks in code :
function _mchid_degree() {
$labels = array(
'name' => _x( 'Degree', 'Taxonomy General Name', '_mchid' ),
'singular_name' => _x( 'Degree', 'Taxonomy Singular Name', '_mchid' ),
'menu_name' => __( 'Degree', '_mchid' ),
'all_items' => __( 'Degrees', '_mchid' ),
'parent_item' => __( 'Degree', '_mchid' ),
'parent_item_colon' => __( 'Degree', '_mchid' ),
'new_item_name' => __( 'Degree', '_mchid' ),
'add_new_item' => __( 'Add New Degree', '_mchid' ),
'edit_item' => __( 'Edit Degree', '_mchid' ),
'update_item' => __( 'Update Degree', '_mchid' ),
'view_item' => __( 'View Degree', '_mchid' ),
'separate_items_with_commas' => __( 'Separate items with commas', '_mchid' ),
'add_or_remove_items' => __( 'Add or remove Education', '_mchid' ),
'choose_from_most_used' => __( 'Choose from the most used', '_mchid' ),
'popular_items' => __( 'Popular Items', '_mchid' ),
'search_items' => __( 'Search Items', '_mchid' ),
'not_found' => __( 'Not Found', '_mchid' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'has_archive' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
);
register_taxonomy( 'degree', array( 'schools' ), $args );
}
From my wp-admin area in the UI, within my custom post type area, I can create a post and assign a degree taxonomy term to that specific post. I can also see that term count is set to 1 because of that.
But! when I edit my custom post template file (single-schools.php) in attempt to show all taxonomy names associated to this post…
$show_it_all = get_queried_object();
echo '<pre>' . var_export($show_it_all, true) . '</pre>';
…it shows me everything about my post except taxonomy information. Why is that?
WP_Post::__set_state(array(
'ID' => 929,
'post_author' => '3',
'post_date' => '2022-08-26 01:59:23',
'post_date_gmt' => '2022-08-26 01:59:23',
'post_content' => '...my content...',
'post_title' => 'Accountant',
'post_excerpt' => '',
'post_status' => 'publish',
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_password' => '',
'post_name' => 'accountant',
'to_ping' => '',
'pinged' => '',
'post_modified' => '2022-09-01 19:48:32',
'post_modified_gmt' => '2022-09-01 19:48:32',
'post_content_filtered' => '',
'post_parent' => 0,
'guid' => 'http://localhost:64069/?post_type=schools&p=929',
'menu_order' => 0,
'post_type' => 'schools',
'post_mime_type' => '',
'comment_count' => '0',
'filter' => 'raw',
))
My Goal – I want to dynamically get “all” taxonomy names that are “associated” to my current post (i.e. ‘degree’,’activity’,’schedule’,’etc’).
Many thanks for any tips!
Leave an answer