Use these actions and filters to extend or modify the plugin functionality.
wpes_meta_keys_query
Filter SQL query for listing meta keys in plugin settings.
Copy Code
/**
* Select all meta keys including those start with _(underscore)
*/
function wpes_meta_keys_query($query) {
global $wpdb;
$query = "select DISTINCT meta_key from $wpdb->postmeta ORDER BY meta_key ASC";
return $query;
}
add_filter('wpes_meta_keys_query', 'wpes_meta_keys_query');
wpes_tax_args
Filter arguments array used by get_taxonomies()
for listing taxonomies in settings.
Copy Code
/**
* Display only custom taxonomies
*/
function wpes_tax_args($args) {
$args['_builtin'] = false;
return $args;
}
add_filter('wpes_tax_args', 'wpes_tax_args');
wpes_post_types_args
Filter get_post_types()
argument array used for listing post type in settings.
Copy Code
/**
* List only custom post types
*/
function wpes_post_types_args($args) {
$args['_builtin'] = false;
return $args;
}
add_filter('wpes_post_types_args', 'wpes_post_types_args');
wpes_enabled
Filter to enable/disable plugin functions for any specific condition.
Copy Code
/**
* Disable WPES when query string variable disable_wpes is true
*/
function wpes_enabled($enabled) {
if (!empty($_GET['disable_wpes'])) {
return FALSE;
}
return $enabled;
}
add_filter('wpes_enabled', 'wpes_enabled');
wpes_posts_search
Filter final search SQL where statement return by posts_search
filter.
Copy Code
/**
* Filter SQL 'where' clause return by WPES
* @see https://developer.wordpress.org/reference/hooks/posts_search/
* @param string $search_where where clause
* @param object $wp_query global wp_query object
* @return string where clause
*/
function wpes_posts_search($search_where, $wp_query) {
$search_where .= " AND your_custom_var = 'your_custom_value'";
return $search_where;
}
add_filter('wpes_posts_search', 'wpes_posts_search', 10, 2);
wpes_meta_keys
Filter meta keys name.
Copy Code
/**
* Insert only one key that start with underscore
*/
function wpes_meta_keys($meta_keys) {
$meta_keys[] = '_key_with_underscore';
return $meta_keys;
}
add_filter('wpes_meta_keys', 'wpes_meta_keys');
wpes_tax
Filter Taxonomies array return by get_taxonomies()
Copy Code
/**
* Insert specific taxonomy in the result returned by get_taxonomies
*
* @param array $taxonomies Array of taxonomies.
* @return array $taxonomies
*/
function wpes_tax($taxonomies) {
$my_tax = (object) [
'labels' => (object) [
'name' => 'Custom Tax'
]
];
$taxonomies['custom_tax'] = $my_tax;
return $taxonomies;
}
add_filter('wpes_tax', 'wpes_tax');
wpes_post_types
Filter post types array return by get_post_types()
Copy Code
/**
* Insert specific post type in the result returned by get_post_types
*
* @param array $post_types
* @return array $post_types
*/
function wpes_post_types($post_types) {
$my_post_type = (object) [
'labels' => (object) [
'name' => 'Custom Post' // "Custom Post" is the name of post type.
]
];
$post_types['custom_post'] = $my_post_type; // "custom_post" is the slug of post type.
return $post_types;
}
add_filter('wpes_post_types', 'wpes_post_types', 10, 1);
wp_es_terms_relation_type
Filter the term relation type OR/AND in search SQL query. This filter will override the WPES setting.
Possible values are OR and AND only.
Copy Code
/**
* If search term contain the specific string 'hello WP' then return OR else use WPES setting
* @return string OR or AND relation between terms in SQL query
*/
function wp_es_terms_relation_type() {
if ($_GET['s'] == 'hello WP') {
return 'OR';
}
}
add_filter('wp_es_terms_relation_type', 'wp_es_terms_relation_type');
disable_wpes
disable_wpes
is a query var. You can pass this query var to your custom queries to disable WPES for specific queries.
This is useful when you do not want to disable WPES for primary query and want to disable for secondary query only thus you can not use wpes_enabled
filter.
Copy Code
/**
* Disable WPES when my_custom_var is set to true.
*/
add_action('parse_query', function ( $q ) {
if ($q->get('my_custom_var')) {
$q->set('disable_wpes', true);
}
});