How to search in Elastic by post titleconcerptcontent?

admin2025-04-19  0

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.

Share Improve this question asked Oct 25, 2019 at 9:36 user177354user177354 1 3
  • I see you are using WP_Query and WordPress by default searches the post title, excerpt and content when the s parameter is specified.. – Sally CJ Commented Oct 25, 2019 at 16:59
  • then again, it returns tons of irrelevant results – user177354 Commented Oct 28, 2019 at 8:40
  • Try asking/searching on the Elastic's forums/site. Questions specific to 3rd party plugins like Elastic are off-topic here. – Sally CJ Commented Oct 28, 2019 at 8:52
Add a comment  | 

1 Answer 1

Reset to default 0

posts_where is a filter, not an action. Also you should concatenate your modification with the query and return $where. Look at the reference.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745054340a282306.html

最新回复(0)