• I’m not sure what’s going on here, so I’m looking for advice.

    When I implement this code:

    $post_type_obj = get_post_type_object('post');
    $taxonomy_names = get_object_taxonomies( 'post' );
    var_dump($taxonomy_names);
    echo "<br><br>";
    var_dump($taxonomy_names); exit();

    I get the following:

    array(0) { } 
    
    array(3) { [0]=> string(8) "category" [1]=> string(8) "post_tag" [2]=> string(11) "post_format" }

    This only happens with the post post_type. If I use a custom post type, both dump out identical arrays. Why are the taxonomies missing from get_post_type_object() but not get_object_taxonomies()? Both pull from a global variable, not the database, I believe.

    Any ideas/help would be appreciated.

    Thanks!

Viewing 1 replies (of 1 total)
  • The answer is that get_post_type_object(‘post’) does not return a post object, but rather a post type object. A post object contains details about a post, such as title and content. A post type object contains details about the type, such as labels for the Admin page and whether the type is hierarchical.

    get_object_taxonomies() requires a post object or the name of a type, not a post type object.

Viewing 1 replies (of 1 total)
  • The topic ‘get_post_type_object for "post" post_type has no taxonomies’ is closed to new replies.