WP CLI commands

WP CLI is a command line interface to WordPress. It’s well-loved by developers for a good reason, as it makes many common WordPress development tasks a breeze.

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

wp relevanssi index

Rebuilds the whole index. This is the fastest and easiest way to rebuild the index.

— post
If you want to index just a single post, define the post ID with this option.

— target=users|taxonomies
Set target to “users” to only rebuild the user profiles and to “taxonomies” to only rebuild the taxonomy terms.

— extend=true|false
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.

— limit
The 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.

— index_debug=true|false
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 refresh

This is a helpful tool for big production sites. This command rebuilds the index (only posts at the moment, not taxonomy terms or users) without emptying the index first. This means the search will continue to work fine during the process. Relevanssi will go through every post and reindex it separately.

There may be limitations on how big a database this command can handle since it needs to load in all the posts at once, but since the command only needs to load in the ID numbers of the posts, there should be no problems refreshing even hundreds of thousands of posts.

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.

— limit
The number of words to display. Defaults to 25.

wp relevanssi read_attachments

Reads the attachment content for all attachments that haven’t been read yet.

wp relevanssi remove_attachment_content

Deletes all attachment content from the posts (i.e. removes all _relevanssi_pdf_content and _relevanssi_pdf_error custom fields). Use with caution! Does not reindex or deindex posts, so you need to run wp relevanssi index or wp relevanssi refresh after this.

wp relevanssi remove_attachment_errors

Deletes all attachment errors from the posts (i.e. removes all _relevanssi_pdf_error custom fields).

wp relevanssi regenerate_related

Flushes all caches for related posts and regenerates new related posts for all posts.

wp relevanssi list_pinned_posts

Lists all pinned or unpinned posts or both.

— format
The format used to display the results. Possible values are “table”, “json”, “csv”, “yaml”, and “count”. Defaults to “table”.

— type
The type of results to list. Possible values are “pinned”, “unpinned”, and “both”. Defaults to “both”.

wp relevanssi list

Lists posts that either are in the index or are not in the index.

— format
The format used to display the results. Possible values are “table”, “json”, “csv”, “yaml”, and “count”. Defaults to “table”.

— type
The type of results to list. Possible values are “post”, “term”, and “user”. Defaults to “post”, which includes all post types, not just posts.

— post_type
Post type to include in the results. Defaults to none, which shows all post types.

— status
Status of the posts to show. Possible values are “indexed” and “unindexed”. Defaults to “indexed”.

Multisite users

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. Please comment on this post if you have any suggestions for possible commands.