0

I have registered 2 custom post types, and 2 custom taxonomies. 1 of my custom taxonomies is applied to both of these CPTs like this:

add_filter('piklist_taxonomies', 'products_taxonomies');
  function products_taxonomies($taxonomies) {
      $taxonomies[] = array(
        'post_type' => array('staff','products')
        ,'name' => 'location'
        ,'show_admin_column' => true
        ,'configuration' => array(
          'hierarchical' => true
          ,'labels' => piklist('taxonomy_labels', 'Location')
          ,'hide_meta_box' => false
          ,'show_ui' => true
          ,'query_var' => true
          ,'rewrite' => array( 
            'slug' => 'location' 
          )
        )
      );
    return $taxonomies;
  }

and

  add_filter('piklist_taxonomies', 'staff_taxonomies');
  function staff_taxonomies($taxonomies) {
      $taxonomies[] = array(
        'post_type' => 'staff'
        ,'name' => 'department'
        ,'show_admin_column' => true
        ,'configuration' => array(
          'hierarchical' => true
          ,'labels' => piklist('taxonomy_labels', 'Department')
          ,'hide_meta_box' => false
          ,'show_ui' => true
          ,'query_var' => true
          ,'rewrite' => array( 
            'slug' => 'staff-department'
          )
        )
      );
  return $taxonomies;
  }

You'll notice that the first taxonomy, 'location', is set to the post type of both staff and products.

When I go to get a list of taxonomies using:

get_taxonomies(array('post_type' => 'staff'), 'names');

It returns 'department' but not 'location' even though it shows up in the admin, and is clearly listed in the array of post_types for this taxonomy. Why doesn't it return 'Locations'?

Furthermore, if I run this:

get_taxonomies(array('post_type' => 'products'), 'names');

It returns an empty string. Why doesn't it return 'Locations'?

Only if I run:

get_taxonomies(array('post_type' => array('staff','products')), 'names');

This will then display 'Locations' but that's not a what I want at that point.

When I query for 'Staff' I want a list of both custom taxonomies associated with 'Staff'. When I query for 'Products': I want to see "locations" returned.

Is there another way to accomplish this?

  • You are getting unexpected results because you are using an unusual method of registering taxonomies. Try using the methods from here: developer.wordpress.org/reference/functions/register_taxonomy – ngearing Sep 8 '16 at 6:14
  • Piklist just provides a wrapper class. The taxonomies are registering as normal and working fine. Is your comment a result of testing that you've done to prove otherwise? – Jeremy Ross Sep 9 '16 at 0:12
  • The code you have provided is un-testable as it is incomplete. – ngearing Sep 9 '16 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.