WordPress.org

Ready to get started?Download WordPress

Forums

Relevanssi - A Better Search
[resolved] Is it possible to restrict to custom field or taxonomy term? (10 posts)

  1. Simon Blackbourn
    Member
    Posted 3 years ago #

    Hi

    Great plugin thanks, I'm just about to go premium!

    I can see that I can restrict searches to a particular post type or within a taxonomy, but is it also possible to restrict to a custom field value or a taxonomy term?

    e.g. where ISBN is a custom field, something like example.com?s=1899964520&custom_field=isbn

    or to search only terms in the genre taxonomy: example.com?s=science&term=genre

    Many thanks
    Simon

  2. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    Both are possible.

    For the first, use example.com?s=189996452&cat=custom. There's a catch, though - you need to specify the custom field used in the source code, it defaults to "custom". This was a hack I built for someone before I knew how to add query variables. Thanks for the reminder, I'll fix this so you can just go &custom_field=isbn. Next version of Premium will have the fix.

    For the second, you can't search for taxonomy terms, but you can restrict searches to certain taxonomy term like this example.com?s=query&taxonomy=genre&term=sciencefiction.

  3. Simon Blackbourn
    Member
    Posted 3 years ago #

    thanks very much for your quick answer.

    i'll keep an eye out for the next version of the premium plugin, that functionality is exactly what i need.

    for the second, here's an explanation: the site will contain 1000s of book reviews, where post_title is the name of the book and post_content is the review. there is a taxonnomy called by where the term is the author's name (the author of the book, not the wordpress post author). the author's name will not appear in the post_title and most likely not in the post_content. so we'd love to have a "search by author" option which only searches the author taxonomy terms, but from what you say it doesn't seem possible.

    so i think i have a solution: i will hook into save_post and add a custom field containing exactly the same data as the taxonomy term, so i can then do a custom field search, e.g. example.com?s=john&custom_field=by.

    if i'm missing a better or more obvious solution do let me know!

  4. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    I've got a book review site as well, and I also have the author of the book in a custom taxonomy.

    I've set it so that the custom taxonomy is indexed. That gets the authors to appear in the search. Users can't search only the authors, but for author search I have a dropdown in the sidebar. I've been fairly satisfied with this, as the search will match both books written by the authors and reviews that mention the author - I think this is better than just searching for authors only.

    Searching only taxonomy terms is not possible, because they are not posts. However, Relevanssi Premium does support searching for user profiles and searching for taxonomy terms is coming, so in the future that option will be available. It just takes some fairly heavy modification in how the search works.

    That solution of yours looks like a good way to deal with it, too.

  5. Niamh2
    Member
    Posted 3 years ago #


  6. Jens Wedin
    Member
    Posted 3 years ago #

    Hi

    Has this been implemented yet?

    /Jens

  7. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    Yes.

  8. Jens Wedin
    Member
    Posted 3 years ago #

    Is this in the premium version?

    Is there a possibility to search for ranges like;

    example.com?s=1910-1920&custom_field=year
    or
    example.com?from=1910&to1920&custom_field=year
    or
    example.com?from=99&custom_field=price

  9. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    None of these are possible with Relevanssi. Relevanssi is not a structured search, but always a free text search.

    What you can do is search for a term in entries that have a certain custom field present (free version) or have a certain value in a certain custom field (Premium).

    If you have, say, addresses in custom fields, you could search for bookstores in Helsinki:

    example.com?s=bookstore&customfield_key=address&customfield_value=helsinki

  10. Jens Wedin
    Member
    Posted 3 years ago #

    Ok, thanks!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags