Custom filters for different posts.
- partsvoithParticipant5 years, 4 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.
partsvoithParticipant5 years, 4 months ago #12083How to divide the output for different types of posts?
(image removed)
partsvoithParticipant5 years, 4 months ago #12086Sorry
(image removed)
partsvoithParticipant5 years, 4 months ago #12088Yes 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?
wpsolrKeymaster5 years, 4 months ago #12089Thanks. 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' ); }
You must be logged in to reply to this topic.