WordPress.org

Ready to get started?Download WordPress

Forums

Relevanssi - A Better Search
2 diferent searchs with 2 diferent filters (19 posts)

  1. Cristiano
    Member
    Posted 3 years ago #

    Hi friends,

    I have a simple issue... I need 2 search boxs in diferent parts of my web:

    - At the first one I need to exclude an especific custom post type
    - At the other I want to search at just this custom post type excluded before...

    I had solved it without the Relevanssi plugin. I assigned the argument exclude_from_search to true for this especific custom post type, so the default search exclude it.

    Then, I created the second search and put the code <input type="hidden" name="post_type" value="that_custom_post_type" /> and it works well.

    But I want to use the Relevanssi´s features, but I couldn´t solve this problem.

    Any help??
    Thanks!

    http://wordpress.org/extend/plugins/relevanssi/

  2. Jens Wedin
    Member
    Posted 3 years ago #

    +1: I would love the same thing :)

  3. cspelts
    Member
    Posted 3 years ago #

    I'm looking for the exact same thing!

  4. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    Well, this almost works with Relevanssi. The problem is with the exclusion, because if you set exclude_from_search and indexing to "all public types", you can't later include.

    So, this'll take some fixing. However, I have a fairly simple solution: support for negative post types.

    You could then do this in the first search:

    <input type="hidden" name="post_type" value="-foo" />

    and this in the second search:

    <input type="hidden" name="post_type" value="foo" />

    And it would work the way you want.

    I'm going to work on Relevanssi a bit today and tomorrow, probably resulting in a new version in couple of days, and I'll include this.

  5. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    Looks like WordPress won't let me do that. I'll have to come up with another solution.

  6. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    I decided to take the easy way out: just replicate WordPress behaviour. What you tried will work with Relevanssi starting from the next version (2.6, probably).

  7. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    Just committed version 2.6, so once that's available, try to see if your original method works.

  8. cspelts
    Member
    Posted 3 years ago #

    Thank you msaari!

  9. Cristiano
    Member
    Posted 3 years ago #

    Ééé!! Thanks msaari! :)

  10. cspelts
    Member
    Posted 3 years ago #

    msaari, this works perfectly! Thank you so much!

    To anyone else, reading the thread later, just to save you some time, here's how I got it working...

    In the WordPress Admin, go to Settings >> Relevanssi, and under "Restrict search to these categories and tags:" I entered the category numbers for all the categories I wanted the main search to index.

    Then I edited my theme, and added a second search field, with a unique "name" and "id" and added this line of code within the form...
    <input type='hidden' name='cat' value='14' />

    So now the main search field searches every category, except for 14, and the second search field only searches category 14 - which is exactly what I was looking for!

    Once again, thank you msaari. It's very cool to express a desire for a certain feature, and then have a solution in less than a day! You rock!

  11. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    I'm glad I could help you.

  12. Cristiano
    Member
    Posted 3 years ago #

    @masaari, I thought it was ok, but I´m afraid it´s not...

    1) I need to restrict the general search to don´t find anything in a especific post type. So, I put the exclude_from_search at this post type arguments...

    2) At the Relevanssi Admin I choose to index 'All public post types' so it excludes my especific post type. Now, the general search is all right.

    3) I want my second search to find posts just in that especific post type, so I add the code <input type="hidden" name="post_type" value="that_custom_post_type" />

    But it doesn´t find anything. I think the 'All public post types' is limiting this search too...

    I´m using the version 2.6.

  13. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    Yes, change "All public post types" to "Everything". That way everything will be indexed, and the exclude from search should restrict the general search as you wish.

  14. Cristiano
    Member
    Posted 3 years ago #

    @msaari If I define it to "Everything" the general search can find my "exclude_from_search" post type...

  15. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    Index everything and check the "Respect exclude_from_search for custom post types:" checkbox.

  16. Cristiano
    Member
    Posted 3 years ago #

    Now is perfect! I didn´t see this checkbox before.
    Thanks again @msaari

  17. gcoghill
    Member
    Posted 3 years ago #

    How did you assign the argument "exclude_from_search" to true for a specific custom post type?

  18. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    Set it in the PHP code where you register the post type. register_post_type().

  19. gcoghill
    Member
    Posted 3 years ago #

    @msaari - thanks! I'm using a plugin to create post types, so will need to dig in some more to see how I can handle this.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags