A plugin to enable Relevanssi research through WP_GraphQL.
This plugin requires Relevanssi >= 4.6.0
and WP_GraphQL >= 0.8.0
.
If you want to retrieve all posts slugs that somehow contains the word "blu":
{
postsSearch(where: {search: "blu"}) {
edges {
node {
slug
}
}
}
}
This obviously works with the entire post parameters (id
, content
, categories
and so on).
You can target one post type at the time. Look at the examples: you can find the default post or the custom post type (which uses Document
as an example).
In case you want the query would be:
{
documentsSearch(where: {search: "blu"}) {
edges {
node {
slug
}
}
}
}
- Check if post_type parameters are consistent with Relevanssi configuration. Currently we assume the query will target the same post types added to Relevanssi configuration.
- Check if Relevanssi plugin has been enabled.
Make sure Relevanssi plugin is active! The plugin currently doesn't check that.
By default GraphQL limits the number of posts. There is currently no way to avoid this limit and it's not suggested. You don't want a all
parameter. You can find more on GraphQL pagination here.
A good compromise is to set the query to a reasonable number:
{
postsSearch(first:25, where: {search: "blu"}) {
...
}
If you need to debug the plugin you can drop this method anywhere in the WP GraphQL functions:
// Use this to debug:
// it stops the function and dumps a value instead of the query result.
ob_start();
var_dump( $the_variable_you_want_to_debug );
$dump = ob_get_clean();
wp_send_json( $dump );