Custom filters for different posts.

  • partsvoith
    Participant
    4 years, 10 months ago #12079

    Good day. Tell me how to make the conclusion of filters only for a specific type of post.

    I have two types of post books and cars. Books have items: author, year of publication, publishing house. The machines attribute: production date, brand, model, and so on. Search filters are displayed immediately for all. How to make a conclusion only for a separate type of post. I tried to do different indexes, it is possible. But when outputting via [solr_search_shortcode], either one index or the second is output. This is logical since the shortcode is one. Thank.

    wpsolr
    Keymaster
    4 years, 10 months ago #12082

    You have two post types with their own fields.

    What do you want to do with them in the search?

    partsvoith
    Participant
    4 years, 10 months ago #12083

    How to divide the output for different types of posts?

    (image removed)

    wpsolr
    Keymaster
    4 years, 10 months ago #12085

    Your image link is broken.

    partsvoith
    Participant
    4 years, 10 months ago #12086

    Sorry

    (image removed)

    wpsolr
    Keymaster
    4 years, 10 months ago #12087

    The image is not clear. Is that 2 pages or one page? Can I see it (them) live?

    partsvoith
    Participant
    4 years, 10 months ago #12088

    Yes of course

    https://wordpress-271504-842505.cloudwaysapps.com/post-book-car/

    Filters immediately for all types of posts. How to make the conclusion of filters for only 1 type?

    wpsolr
    Keymaster
    4 years, 10 months ago #12089

    Thanks. You can use the filter WPSOLR_Events::WPSOLR_ACTION_SOLARIUM_QUERY, to add your post type filter.

    Example in file /wp-content/plugins/wpsolr-pro/wpsolr/pro/extensions/woocommerce/class-wpsolr-plugin-woocommerce.php:

    add_action( WPSOLR_Events::WPSOLR_ACTION_SOLARIUM_QUERY, [$this,'wpsolr_action_query',], 10, 1 );

    public function wpsolr_action_query( $parameters ) {
    
     /* @var WPSOLR_Query $wpsolr_query */
     $wpsolr_query = $parameters[ WPSOLR_Events::WPSOLR_ACTION_SOLARIUM_QUERY__PARAM_WPSOLR_QUERY ];
    
     /* @var WPSOLR_AbstractSearchClient $search_engine_client */
     $search_engine_client = $parameters[WPSOLR_Events::WPSOLR_ACTION_SOLARIUM_QUERY__PARAM_SOLARIUM_CLIENT ];
    
     /* Add any custom post type filter here */
     $search_engine_client->search_engine_client_add_filter_term( 'my_filter_by_type', WpSolrSchema::_FIELD_NAME_TYPE, false, 'book' );
    
    }
Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.