Forums

get_taxonomies() doesn't return the expected result (1 post)

  1. Dzikri Aziz
    Member
    Posted 5 months ago #

    Hello,

    In the front-end, I needed to get a post type taxonomies, so I did:

    $taxonomies = get_taxonomies( array(
      'public'      => true,
      'object_type' => array('post')
    ), 'objects', 'and' );

    this worked fine, I got both tags and catgories objects.

    But then, I registered a custom post type:

    function my_custom_post_types() {
      register_post_type('work', array(
        'labels'        => array('name' => __('Works'), 'singular_name' => __('Work'),
        'public'        => true,
        'supports'      => array('title', 'editor', 'thumbnail'),
        'taxonomies'    => array( 'post_tag' )
      ));
    }
    add_action( 'init', 'my_custom_post_types' );

    Now the $taxonomies on the front-end only contains category (no post_tag). Only after changing the $operator argument to or I can get the post_tag object back, but I need to use and.

    I'm not really sure what I did wrong, so any hints are welcome.

Reply

You must log in to post.

About this Topic