• Resolved mikiamomik

    (@mikiamomik)


    Hi,
    I use elasticsearch in Author and Search Page in the main site of a Network.
    I need to exclude a term of taxonomy from elastic search query

    
        add_action('pre_get_posts',  function($query){
            $query->set('ep_integrate', false);
            if ($query->is_main_query() && ($query->is_search || $query->is_author)) {
                $query->set('ep_integrate', true);
                $query->set('tax_query', array(
                    array(
                        'taxonomy' => 'MYTAX',
                        'terms' => array('no-index'),
                        'field' => 'slug',
                        'operator' => 'NOT IN',
                    ),
                ));
            }
        }, 999);

    This doesn’t work!

    So i’m trying with another filter

    
        add_filter('ep_index_posts_args', function ($args){
            $args['tax_query'] = array(
                array(
                    'taxonomy' => 'MYTAX',
                    'terms' => ['no-index'],
                    'field' => 'slug',
                    'operator' => 'NOT IN',
                ),
            );
            return $args;
        }, 0, 1);

    But it seems doesn’t work!

    Obviously the term ‘no-index‘ exists in all sites (differente term-id, for this reason i use the slug).
    Without ep_integrate filter works!

    How can i solve this problem?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi there!

    Did you manage to fix this problem?

    I am using ElasticSearch for the first time and I have a custom main query on my wordpress installation, I remove a category from it, but I can’t manage to make it works.

    function remove_home_category( $query ) {
        if( ( !is_admin() && $query->is_main_query() ) && ( $query->is_search() || $query->is_tag() || !$query->is_category(2631) ) ) {
            $query->set( 'ep_integrate', false );
            $query->set( 'cat', '-2631' );
        }
    }

    If i set ep_integrate true all my posts dissapear…

    Plugin Contributor vhauri

    (@vhauri)

    Hi,

    All support for ElasticPress is provided via our Github issues page: https://github.com/10up/ElasticPress/issues/

    Please share your issue report there and be sure to include all requested information from the template.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude taxonomies’ is closed to new replies.