0
votes

I have about a dozen Event Categories and 1 Post Category

When I use get_categories($args) where:

$args=array(
  'orderby' => 'name',
  'order' => 'ASC',
  'hide_empty' => 0
);

I get the Post Category (which I want) and all the Event Categories (which I don't want).

I can't quite figure out the parameters to pass get_categories in order to see categories associated with posts only and not events. I've read a little bit about using get_terms() to do this and tried:

$args = array('type'=> 'post', 'order' => 'ASC', 'hide_empty' => 0 );
$taxonomies = array('category');
$terms = get_terms( $taxonomies, $args);

but this gives me the exact same results - my 1 post category and my dozen event categories.

Mark

2
Is "events" its own taxonomy that you registered, and event categories are categories that belong to this taxonomy? - C. E.
I didn't do this explicitly, but I think a plugin did. I've installed the All-in-One Event Calendar by Timely then I clicked on Events and entered a bunch of Event Categories. Could I check this out by looking at the wp_term table, finding one of my Event Categories, noting its term_id then finding that term_id in wp_term_taxonomy and noting the value in the taxonomy column? - user1126515
You can find this out by looking at the links in the admin interface. If you have a menu link "Events" in the admin interface which ends in ?post_type=... then there is the name of your custom post type. In the sub menu you'll find taxonomies, if you hover one of those links the URL will end in ?taxonomy=...&posty_type=... so there is the name of your taxonomy. Take a look at those two links, it's important to know exactly what the setup is because it's bit odd, what you're getting. It's set to only retrieve post categories by default... so it suggest those are post categories, not event. - C. E.
The "Events" menu link ends in post_type=ai1ec_event. The Events Category link (which displays in the Events menu) ends in taxonomy=events_categories&post_type=ai1ec_event This all tells me the custom post type is ai1ec_event and the taxonomy is events_categories. And none of this explains the results I'm getting. - user1126515

2 Answers

0
votes

To get categories from your taxonomy (as given in the comments), events_categories, use

$categories = get_categories( array( 'hide_empty' => 0, 'taxonomy' => 'events_categories' ) );

To be honest, I'm surprised that your original query returned categories belonging to the events_categories taxonomy. It should only return post categories. This should be fail safe however. It can only return categories belonging to the specified taxonomy.

0
votes

Turns out All-In-One Event Calendar has an option to include/exclude Event Categories with Post Categories.

Mine was set to include. I don't know if that's the default or not.

Once I turned it off, the following:

get_categories($args=array'orderby' => 'name', 'order' => 'ASC','hide_empty' => 0);

gave me the Post Categories as I wanted.

Thanks very much for all the help, this was most instructive.