WordPress.org

Ready to get started?Download WordPress

Forums

Relevanssi - A Better Search
[Plugin: Relevanssi] Resricting by Taxonomy? (18 posts)

  1. bgajus
    Member
    Posted 3 years ago #

    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.

    ?s=books&genre=fiction

    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.

  2. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

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

  3. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

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

  4. bgajus
    Member
    Posted 3 years ago #

    Awesome! Looking forward to 2.0!!

  5. bgajus
    Member
    Posted 3 years ago #

    msaari,
    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.

  6. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    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?

  7. bgajus
    Member
    Posted 3 years ago #

    my query looks something like this...

    ?s=search_term&taxonomy=term

    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.

  8. bgajus
    Member
    Posted 3 years ago #

    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 ) );
    }

  9. bgajus
    Member
    Posted 3 years ago #

    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

    ?s=processor&systems=dell

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

  10. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    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.

  11. bgajus
    Member
    Posted 3 years ago #

    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.

  12. bgajus
    Member
    Posted 3 years ago #

    Any ideas?

  13. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    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.

  14. bgajus
    Member
    Posted 3 years ago #

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

  15. gcoghill
    Member
    Posted 3 years ago #

    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?

  16. gcoghill
    Member
    Posted 3 years ago #

    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.

  17. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    Yes, as it says in the plugin documentation: "Known issue: Custom post types and private posts is problematic - I'm using default 'read_private_*s' capability, which might not always work."

    You've bumped into a situation where it doesn't work. Unfortunately I don't have a good suggestion in hand, except maybe to remove the private posts from the index.

  18. gcoghill
    Member
    Posted 3 years ago #

    @msaari - thanks, yeah I noticed that in the documentation after I posted this. Not a huge issue, I'm just usin private posts while I set up a new site. Great plugin!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic