Skip to main contentSkip to footer

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.
  • media: Attachment content (coming in the next version).
  • 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.

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 supported.

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 the 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.

Search for posts that have the phrase “Reiner Knizia” in the taxonomy “designers”:

{designers:"reiner knizia"}

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Indexing and searching PDFs in WordPress

…service on a separate server. Which PDF files can you index? Since Relevanssi is a WordPress search, Relevanssi operates on WordPress posts (including all the different post types). So, to have Relevanssi index your PDFs, they need to be WordPress posts. That’s fortunately really simple: upload your PDF files to……in Relevanssi-generated excerpts, you can check the “Use custom fields for excerpts” option (because Relevanssi keeps the attachment content in custom fields). Do note that generating excerpts is the slowest part of searching to start with, and if your PDFs have lots of text, enabling this option may make the…

Debugging indexing problems

The easiest way to debug indexing problems is to use the WP CLI tools available in Relevanssi Premium. To see how Relevanssi sees the post 123, just use the following command on the command line: wp relevanssi index –post=123 –index_debug=true This will print out how Relevanssi sees the post, how……it appears in the different steps of the indexing process and the database queries Relevanssi uses to save the post data. If WP CLI is not available or you are using free Relevanssi, this’ll do pretty much the same thing: add_action( ‘wp‘, function() { if (is_user_logged_in()) { relevanssi_index_doc( 123, false,…

Simple French plurals
If you have Relevanssi Premium and want to make Relevanssi understand French plurals, you can add this code to your…

Related Posts:

Currently there are no related posts available.

Comment Section:

3 Comments. Leave new

  • Hello, mr. Saari! Can you please help to understand where is needed use {target:search_term} exactly? May be it is needed to use hooks like relevanssi_modify_wp_query to modify search terms from backend? Thank you!

    Reply
    • It can be used in search terms anywhere where you want to target a specific part of the post with a search. Since it’s a bit clunky to use, I wouldn’t expect your site visitors to use it – though they can – so it’s best used in computer-generated queries. The original reason why I added it was to make Related posts queries more accurate. When you restrict the Related posts queries to only target tags with tag keywords, this is what Relevanssi uses to do that.

      So you don’t need any hooks, code or anything like that: just use it in the search terms.

      Reply

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed