Filter the search results by taxonomy

  • wpsolr
    Keymaster
    5 years, 4 months ago #8655

    If you send me your code, I’ll add it to the documentation.

    pseudo visitor
    Participant
    5 years, 4 months ago #8656

    It’s basically the same code.

    It was kinda stupid on my side, but I forgot that I was experimenting with the plugin’s hooks yesterday, so I had some spread out throughout the website. That’s why it was giving me that error I sent you. When I removed that, I just used the code I’m leaving you below in my theme’s functions.php and it worked correctly ????

    use wpsolr\core\classes\WPSOLR_Events;
    
    use wpsolr\core\classes\WpSolrSchema;
    
    add_action(WPSOLR_Events::WPSOLR_ACTION_SOLARIUM_QUERY, 'wpsolr_action_query', 10, 1);
    
    function wpsolr_action_query($parameters)
    
    {
    
    /* @var WPSOLR_AbstractSearchClient $search_engine_client */
    
    $search_engine_client = $parameters[WPSOLR_Events::WPSOLR_ACTION_SOLARIUM_QUERY__PARAM_SOLARIUM_CLIENT];
    
    $taxonomy_name = 'tax-name';
    
    /** * Create a "not exists" filter */
    
    $filter_not_exists_terms_in_taxonomy = $search_engine_client->search_engine_client_create_not($search_engine_client->search_engine_client_create_filter_exists($taxonomy_name . WpSolrSchema::_SOLR_DYNAMIC_TYPE_STRING));
    
    $search_engine_client->search_engine_client_add_filter("not in taxonomy {$taxonomy_name}", $filter_not_exists_terms_in_taxonomy);
    
    }

    And again, thanks a lot for your help!

Viewing 2 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic.