10up / ElasticPress

A fast and flexible search and query engine for WordPress.
https://elasticpress.io
GNU General Public License v2.0
1.23k stars 312 forks source link

Combining elastic search with tax_query #3908

Closed jacobmasters closed 1 month ago

jacobmasters commented 2 months ago

Is your enhancement related to a problem? Please describe.

I've a simple external page which just includes the wp-config file and disables all themes/most plugins to just run a simple get_posts search:

<? define('WP_USE_THEMES', false); define('plugins-searchonly',true); require("../wp-config.php"); remove_filter('pre_get_posts', 'pre_get_filter'); $args = array('ep_integrate' => true,'posts_per_page' => -1,'post_type' => 'attachment','post_status' => 'any'); $args = array_merge( $args, array('s' => $_GET['search'])); $taxquery = array('tax_query' => array( array('taxonomy' => 'image-association','field' => 'slug', 'terms' => array('folio')))); $args = array_merge($args,$taxquery); $folios = get_posts($args) ; ?>

Currently wp-admin searches to attachments use Elasticsearch, so the index is in place, but using the stripped back code above does not and returns 0, does any global variable or wordpress element need including for it to work in this way?

Designs

No response

Describe alternatives you've considered

No response

Code of Conduct

jacobmasters commented 2 months ago

Started this as a headless issue, but in further testing its actually the tax_query addition to the search query that's throwing this out and resulting 0 results, is there a way to combine the two or do i need to filter after search?

felipeelia commented 2 months ago

If you are sure ElasticPress is being loaded, that code should work, @jacobmasters. Is that image-association taxonomy indexable? If not, you may need to use the ep_sync_taxonomies filter to add it to the list.

github-actions[bot] commented 1 month ago

It has been 3 days since more information was requested from you in this issue and we have not heard back. This issue is now marked as stale and will be closed in 3 days, but if you have more information to add then please comment and the issue will stay open.

github-actions[bot] commented 1 month ago

This issue has been automatically closed because there has been no response to our request for more information in the past 3 days. With only the information that is currently available, we are unable to take further action on this ticket. Please reach out if you have found or find the answer we need so that we can investigate further. When the information is ready, you can re-open this ticket to share it with us.