Posted on

Taxonomy page search

To include taxonomy pages (categories, tags, custom taxonomies) in the search, enable the option in the options page. There’s also the option to choose which taxonomies are included. By default everything is indexed.

Currently the title of the taxonomy is indexed with the description field. Indexing other fields isn’t currently possible. Taxonomy pages should be automatically updated in the index whenever they are edited.

In the search results template, avoid get_permalink(), as it doesn’t work. the_permalink() works and returns the correct permalink. You can use relevanssi_get_permalink(), if you don’t want to echo the permalink directly.

In the post object created from the taxonomy page, $post->post_title contains the name of the taxonomy, $post->post_content has the description, $post->link has the permalink and $post->post_type will contain the name of the taxonomy.

If you want to modify the post objects Relevanssi creates from the taxonomies, you can use the relevanssi_taxonomy_term_to_post filter.

27 comments Taxonomy page search

  1. I’m using the free version. At the moment the search result shows the product title and the whole description. However i’d like it to show the product image (the 1st one would be fine) and the price. Is it possilbe?? Any help would be highly appreciated! Many thanks.

    1. That is just a question of setting up your search results template to show the product image and price. That should not be particularly tricky, given some HTML and PHP understanding.

      1. Thank you vvvvvvvvvery much for the reply. The guy who set up the website for me has gone and i’m on my own now:(. So should i do it in relevanssi/relevanssi.php file or somewhere else? Sorry for asking such a silly question but i’m not a technical person at all. Many thanks!

        1. No, you’re not supposed to touch the Relevanssi plugin files at all. The search results template is actually part of your theme, and can usually be found in the search.php file in your theme folder.

          If you’re not a technical person at all, I recommend hiring someone to do it for you, as it probably requires some PHP knowledge. Anybody with a decent level of WP theme knowledge can do it.

  2. i sell books and using your free plugin to search in my store. i really like it, only i am not succeeding with the taxonomy search. i add my “author” taxonomy to “Custom taxonomies to index” but when i search for an author name it doesnt show any result.

    reading here i understand its a premium option only, or am i doing something wrong?

    1. I’m guessing here, but I think the problem may be caused by a conflict, since “author” can also mean the author of the post. Try renaming your taxonomy to “book_author”. That might help.

      Finding posts by taxonomy is available in free version, it’s just finding taxonomy term pages is restricted to premium.

  3. Hi. In my site, Relevanssi is not indexing custom post type. They are marked like public and not excludad from search, even Relevanssi is not respecting this trought options page. ¿What can be hapennig? WP 3.5, Relevanssi Free last versión.
    Regards!

    1. There is usually a reason. Are you sure Relevanssi is not indexing it? Do the custom posts not appear in the database? It can be that Relevanssi is indexing them fine, but the problem is in searching.

  4. I have the premium version installed and configured to index my taxonomies, including a custom taxonomy. When searching, these taxonomy pages are not coming up in the results. Isn’t this supposed to be possible with the premium version?

    1. Yes, that is supposed to be possible. You’ve checked the correct taxonomies on the *lower* list of “taxonomies to index” on the Relevanssi settings page? You’re sure you’re getting your search results from Relevanssi?

  5. We’d like to be able to restrict the search results to a Page in the current section of the site where the user is. A section of the site is a Folder for a Page. Here’s an example of the hierarchy with Pages:

    site.com/bicycle/abcpage
    site.com/bicycle/defpage
    site.com/bicycle/tirestuff/ghipage

    site.com/moped/abcpage
    site.com/moped/defpage

    I would want the site to either search all bicycle pages or all moped Pages. In my research through your documentation I’ve found ways to use categories and tags for Posts, and it appears that you recommend Taxonomies for Pages. Should I use a custom field to create a (seemingly duplicate) Taxonomy on all of my pages within a certain section, or is there a simpler way to simply filter results to the “bicycle” or “moped” folders?

    Thanks so much for your help!

  6. This might sound strange, but I could not find an answer to this:
    Does this setting allow me to find posts from the selected taxonomies or should it show an actual link to the taxonomy-archive?

    1. It shows a link to the taxonomy term page. The other taxonomy setting (the one that is available in free Relevanssi) will find the posts that have the taxonomy term present.

  7. I’m using the free option. Have a custom post type with it’s own set of categories/taxonomy. The front end searches the posts fine. It does not bring up the category pages. The back end finds nothing in the posts but does work for the categories.

    Is this a free/premium issue or am I just not adjusting the settings properly?

  8. Hi i am using relevanssi premium which is a great plugin, I have custom taxonomies with different fields and description in it. I want to show relevant fields archive page when user types for particular word. Relevanssi gets it on the first result but read more button goes to home page for some reason any help would be appreciated

    1. Relevanssi used to include taxonomy terms even when the search was restricted by a post_type parameter, but that caused enough complaints that the default behaviour was changed. If you want taxonomy terms in the search, add the taxonomy name to the post_type parameter.

      1. I have such many custom taxonomies that i will loose flexibility when i write it hard coded. If i left it blank i’ve got all of them and can customize by WP Panel in plugin settings. Am i right ?

        1. Yes, no “post_type” restriction in the search means all taxonomies are included. If the “post_type” restriction never changes, it’s best done in Relevanssi indexing settings, but you can also use “relevanssi_hits_filter” to weed out posts.

          1. Yeah, I just discover this becouse of my custom query for search wich is required for my AJAX implementation. So i’ve done it via relevanssi_do_query() function. Thanks anyway 😉

  9. Dear Mikko,

    I’m currently developing my website, and have installed your plug-in.

    There are two different pages A and B on my website where I’d like to insert Relevanssi search forms: form As for A and form Bs for B.

    Both forms need to search through pages with a specific taxonomy only, that is:

    As needs to search through pages with the tag ‘ads’ only.
    Bs needs to search through pages with the tag ‘statistics’ only.

    I think this might not be so complicated, but I don’t know how to do it.
    Do I need to insert some code in the html form code, in the search php code or in both?

    Any help would be greatly appreciated.

    Best,

    Luca

Leave a Reply

Your email address will not be published. Required fields are marked *