0

I have different categories that require different filters

For example a 'training' can be about a specific bodypart, by a specific athlete,..

What I want is something like this: enter image description here

But different versions of this for different categories.

I'm fairly new to wordpress development, but I have everything set up, made my own theme. The only thing left are these custom fiters.

How exactly should I accomplish this? Could I for example use custom filters to say: "Body part: shoulder", and then create a filter on custom fields inside a category?

Thanks in advance.

0

I think these should be separate taxonomies. Category is actually a taxonomy in its own right.

You would create a taxonomy for each of the filters/drop-downs. This may seem like overkill but i think it will make it easier to work on additional features down the road.

Add the following method to your functions.php. Replace 'rwc' with your theme's domain:

function add_taxonomy($singular, $plural, $objects) {
$labels = array(
    'name'                => _x( $plural, 'General Name', 'rwc' ),
    'singular_name'       => _x( $singular, 'Singular Name', 'rwc' ),
    'menu_name'           => __( $plural, 'rwc' ),
    'parent_item_colon'   => __( 'Parent '.$singular.':', 'rwc' ),
    'all_items'           => __( 'All '.$plural, 'rwc' ),
    'view_item'           => __( 'View '.$singular, 'rwc' ),
    'add_new_item'        => __( 'Add New '.$singular, 'rwc' ),
    'add_new'             => __( 'Add New '.$singular, 'rwc' ),
    'edit_item'           => __( 'Edit '.$singular, 'rwc' ),
    'update_item'         => __( 'Update '.$singular, 'rwc' ),
    'search_items'        => __( 'Search '.$plural, 'rwc' ),
    'not_found'           => __( $singular.' Not found', 'rwc' ),
    'not_found_in_trash'  => __( $singular.' Not found in Trash', 'rwc' ),
);             
    $args = array(
      'hierarchical'        => true,
      'labels'              => $labels,
      'show_ui'             => true,
      'show_admin_column'   => true,
      'query_var'           => true,
      'rewrite'             => array('slug' => strtolower($singular))
    );
    register_taxonomy(strtolower($singular), $objects, $args);        
}

Then use it to add taxonomies. Replace 'post' with 'page' if you are looking to filter pages

function add_custom_taxonomies() {
    $objects = array('post');

    add_taxonomy('Gender', 'Genders', $objects);
    add_taxonomy('Level', 'Levels', $objects);
    // .. and so on
}
add_action( 'init', 'add_custom_taxonomies', 0 );
  • Thanks for you answer! I've never worked with taxonomies before, anything specific I should know/read before I add your code? How do I assign posts to a taxonomy in the post editor? (sorry for all the questions) – vlovsky Apr 3 '15 at 8:33
  • The only thing i can think of that may be affected by this is the structure of your permalinks. So that is something to consider if you are using %category% in your permalink structure. For instance, with categories only (no new taxonomy) you could build hierarchical urls such as this: female/advanced/some-athlete/triceps. I don't think you can get the same thing using custom taxonomies out of the box. I'm sure there are ways around that though. – td-lambda Apr 3 '15 at 8:38
  • Thanks again for your answer. How would I let the taxonomies display as dropdowns in a specific category page? – vlovsky Apr 3 '15 at 8:51
  • Check out the wp_dropdown_categories function: codex.wordpress.org/Function_Reference/wp_dropdown_categories. You would call it for each dropdown (with the taxonomy name: 'taxonomy' => 'taxonomy-name-here'). You can also check out the source for it in wp-includes/category-template.php – td-lambda Apr 3 '15 at 8:55
  • Then here is an example for querying using multiple taxonomies/selections: wordpress.org/support/topic/… – td-lambda Apr 3 '15 at 8:57

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.