Support » Plugin: Relevanssi - A Better Search » [Plugin: Relevanssi] Resricting by Taxonomy?

  • msaari,

    was wondering if there is a way to restrict search results to a taxonomy term similarly to how you can restrict to a post_type?

    I tried something like below but it didn’t change the results.


    where genre is the Custom Taxonomy and fiction is the term/category.

    When you create a custom taxonomy you can make it hierarchical much like categories. So you can create a taxonomy called Genre and create category like terms in Genre.

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author Mikko Saari


    Yes, I suppose it can be done. If it can be done, version 2.0 is coming out this week and will have it.

    Plugin Author Mikko Saari


    This is actually a WordPress supported feature. Cool. Done.

    Awesome! Looking forward to 2.0!!

    thanks for the update. i was wondering if you had tried this functionality out….to restrict by taxonomy. it does not appear to be working on my end. I’m getting 0 results nothing found.

    Plugin Author Mikko Saari


    It works for me, without restriction and with restriction the results are different, as they should.

    I know there’s a restriction that only one taxonomy term can be used. The terms are case insensitive.

    So, tell me more – what are you trying to do and what should happen?

    my query looks something like this…


    I’m pretty sure that is the correct structure. I’m using a plugin called GD CPT Tools that basically is a web interface to build custom taxonomies and post_types. I’m wondering if that plugin is causing a problem. My next step is to manually create the taxonomies and see if it works then. I’ll let you know.

    yeah still getting the “search found nothing” results. I disabled every plugin too. Not sure if this helps but here is the code i used to register the post_type and taxonomies….

    // The register_post_type() function is not to be used before the ‘init’.
    add_action( ‘init’, ‘my_custom_init’ );

    /* Here’s how to create your customized labels */
    function my_custom_init() {
    $labels = array(
    ‘name’ => _x( ‘KB Articles’, ‘post type general name’ ), // Tip: _x(”) is used for localization
    ‘singular_name’ => _x( ‘KB Article’, ‘post type singular name’ ),
    ‘add_new’ => _x( ‘Add New’, ‘kb_article’ ),
    ‘add_new_item’ => __( ‘Add New KB Article’ ),
    ‘edit_item’ => __( ‘Edit KB Article’ ),
    ‘new_item’ => __( ‘New KB Article’ ),
    ‘view_item’ => __( ‘View KB Article’ ),
    ‘search_items’ => __( ‘Search KB Article’ ),
    ‘not_found’ => __( ‘No kb articles found’ ),
    ‘not_found_in_trash’ => __( ‘No kb articles found in Trash’ ),
    ‘parent_item_colon’ => ”

    // Create an array for the $args
    $args = array( ‘labels’ => $labels, /* NOTICE: the $labels variable is used here… */
    ‘public’ => true,
    ‘publicly_queryable’ => true,
    ‘show_ui’ => true,
    ‘query_var’ => true,
    ‘rewrite’ => true,
    ‘capability_type’ => ‘post’,
    ‘hierarchical’ => false,
    ‘menu_position’ => null,
    ‘supports’ => array( ‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘comments’ )

    register_post_type( ‘kb_articles’, $args ); /* Register it and move on */

    // Custom Taxonomy Code
    add_action( ‘init’, ‘build_taxonomies’, 0 );

    function build_taxonomies() {
    register_taxonomy( ‘systems’, ‘kb_articles’, array( ‘hierarchical’ => true, ‘label’ => ‘Systems’, ‘query_var’ => true, ‘rewrite’ => true ) );
    register_taxonomy( ‘kb_categories’, ‘kb_articles’, array( ‘hierarchical’ => true, ‘label’ => ‘KB Categories’, ‘query_var’ => true, ‘rewrite’ => true ) );
    register_taxonomy( ‘kb_tags’, ‘kb_articles’, array( ‘hierarchical’ => false, ‘label’ => ‘KB Tags’, ‘query_var’ => true, ‘rewrite’ => true ) );

    So, tell me more – what are you trying to do and what should happen?

    I’m trying to filter out search results using one of my custom taxonomies called systems and any term under systems.

    so my url query looks like this


    right now it’s telling me there are 0 results from my search but I know it should be returning results.

    Plugin Author Mikko Saari


    Ah, you’re using custom post types – are you sure Relevanssi is indexing that custom type? That might cause the problems.

    In any case, even if it’s a bug in my code, I’m almost sure it has something to do with the fact that you’re using a custom post type.

    I’m using a custom post type that has custom taxonomies associated with it. I’ve checked my Relevanssi settings and I’ve got it set to include Everything in the index but just in case I’ve also tried adding the custom post type as well as having all the custom taxonomies added. Every time it brings back 0 results.

    Any ideas?

    Plugin Author Mikko Saari


    No idea right now, this looks like something I have to test a bit to see if there’s something fundamentally wrong in the way Relevanssi handles custom post types and taxonomies – both do work individually, but apparently not together.

    Sounds good. I’ll keep an eye out for updates.

    I’m using version 2.7.3 and not sure if the custom post type & custom taxonomy combo is working with the plug in. Doesn’t seem to. Anyone know what the status is?

    It seems the issue is that Relevanssi will not pick up Private posts that use either a custom post type, or custom taxonomy (haven’t figured out which, since I am using both for the site).

    Once I publicly published a post using a custom post type, it found the custom taxonomy in the search.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘[Plugin: Relevanssi] Resricting by Taxonomy?’ is closed to new replies.