Posted on

Target specific part of the post

Relevanssi Premium 2.4.4 introduced a new feature where you can target specific parts of the post straight from the search terms. The format for this is

{target:search_term}

Target can be one of the following:

  • title: Post title.
  • content: Post content.
  • author: Author display name.
  • comment: Comment text.
  • link: Link from another post.
  • excerpt: Post excerpt.
  • taxonomy slug: Taxonomy name (use tag or post_tag for tags, category for categories and the taxonomy slug for other taxonomies).
  • custom field name: Custom field name.
  • MySQL column name: Name of a custom MySQL column.

These are all compared against Relevanssi index, so you can use any of these targets only if Relevanssi indexes that particular type of content: if you want to, say, target excerpts, you need to make sure Relevanssi is set to index the excerpt.

The search term must be a single word, so if you want to target multiple words, use a specifier for each word separately. Phrases are not supported at the moment.

Examples:

Search for word “cat” in titles only:

{title:cat}

Search for word “dog”, but only in tags:

{tag:dog}

Search for posts that have the word “knizia” in taxonomy “designers” and the word “dutrait” in the taxonomy “illustrators”:

{designers:knizia} {illustrators:dutrait}

Note that for multiple targeted terms, you need to have a space between the terms.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.