Im trying to make Wordpress to search in Elastic by some restriction:
$args['ep_integrate'] = true;
add_action( 'pre_get_posts', function( $query ) {
// what to write here to search in "title", "excerpt", "content" only?
});
$query = new WP_Query($args);
I was tryting to modify the query:
$args['ep_integrate'] = true;
add_action('posts_where', function($where) {
return ' posts.ID = 234234';
// return ' post_title LIKE "%paff%" OR post_contents LIKE "%paff%" OR post_excerpt LIKE "%paff%";
}, 10,2);
$query = new WP_Query($args);
but its like I didnt set anything, it still returns bunch of result instead of one.
Im trying to make Wordpress to search in Elastic by some restriction:
$args['ep_integrate'] = true;
add_action( 'pre_get_posts', function( $query ) {
// what to write here to search in "title", "excerpt", "content" only?
});
$query = new WP_Query($args);
I was tryting to modify the query:
$args['ep_integrate'] = true;
add_action('posts_where', function($where) {
return ' posts.ID = 234234';
// return ' post_title LIKE "%paff%" OR post_contents LIKE "%paff%" OR post_excerpt LIKE "%paff%";
}, 10,2);
$query = new WP_Query($args);
but its like I didnt set anything, it still returns bunch of result instead of one.
posts_where
is a filter, not an action. Also you should concatenate your modification with the query and return $where
. Look at the reference.
WP_Query
and WordPress by default searches the post title, excerpt and content when thes
parameter is specified.. – Sally CJ Commented Oct 25, 2019 at 16:59