WP CLI is a command line interface to WordPress. It’s well-loved by developers and for a good reason, as it makes many common WordPress development tasks a breeze to do.
Relevanssi includes some tasks that can well be done from the command line and since adding new commands to WP CLI is very simple, Relevanssi Premium has WP CLI support from version 1.15.1 onwards.
This document describes the WP CLI commands available for Relevanssi. For the exact list of commands available on your installation of WordPress and Relevanssi, see
wp help relevanssi.
wp relevanssi index
This is the most useful command in my opinion. Rebuilding a big index can be a painful process, with the server timing out and all that. That’s history! Just go to the command line and type
wp relevanssi index and watch the index getting built.
If you want to index just a single post, define the post ID with this option.
target to “users” to only rebuild the user profiles, and to “taxonomies” to only rebuild the taxonomy terms.
If for some reason you can’t rebuild the whole index at one go, setting this to true will continue the indexing from where it was left. The document limit will be taken from the settings page, unless the limit parameter is used.
Number of posts you want to index at one go. If you are extending the indexing, the
relevanssi_index_limit option is used for limit if this value is left empty.
If you want to debug indexing issues, you can enable this setting and index just one post with the
post option – this doesn’t do anything when indexing the whole database – to see the post as Relevanssi sees it.
Here’s how you can index all sites in your network:
wp site list --field=url | xargs -n1 -I % wp --url=% relevanssi index
wp relevanssi truncate_index
This command is used to truncate the Relevanssi index.
wp relevanssi add_stopword
Adds stopwords to the list of stopwords and removes those words from the index. Just list any number of stopwords after the command, separated with spaces.
wp relevanssi remove_stopword
Removes stopwords from the list of stopwords. This can’t return the stopwords back to the index, so remember to rebuild the index after removing the stopwords.
wp relevanssi reset_log
Empties out the
wp_relevanssi_log database table. Use with caution, you can’t undo this command.
wp relevanssi common
Shows the 25 most common words in the index. These are prime stopword candidates.
The number of words to display. Defaults to 25.
If you are running a multisite setup, remember that you need to use the
--url parameter to define which site you want to access.
Suggestions for commands?
I’m interested in developing the WP CLI support further. These were my first ideas of what can be done with Relevanssi Premium and WP CLI. If you have any suggestions for possible commands, please comment on this post.