• I have a site where there are events that have categories attached to them. I want to be able to filter the events by the categories by using the slugs as CSS classes. Problem is the filter is limited to top-level categories and events can have multiple categories attached to them.

    For instance, the categories could look like this:

    –Dance
    –Music
    —-Pop
    —-Rock
    –Theatre

    What I’m aiming for is to be able to handle it if a user selected “Dance” and “Rock” and have the CSS classes of “category-dance”, “category-rock”, AND “category-music”.

    The post_class() does fine for getting the multiple categories taken care of (showing “category-dance” and “category-rock”), but I’m struggling to figure out how to add the top-level parent category (“category-music”) to the list.

    I’m sorry, but the site is currently in a dev environment and not publicly accessible. ??

    Do you have any suggestions that might help?

Viewing 1 replies (of 1 total)
  • Hi. Its not a solution but could be a hint, I hope.

    <?php
      $catobj = get_category_by_slug( 'rock' );// get category slug somehow
      $parent_id = $catobj->category_parent;
      if ( !empty($parent_id) ){// when parent category exists
        $parentname = get_the_category_by_ID( $parent_id );
        var_dump($parentobj);
      }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Multiple Post Categories PLUS Parent Categories’ is closed to new replies.