Exclude posts based on custom acf field value
-
prakashreddy.imduriParticipant8 months, 2 weeks ago #31061
Hi, How can we exclude a custom field set to No, in product data. I tried this code and also use pre_get_posts, still nothing worked. Can you suggest solution for this.
// functions.php //
add_filter(WPSOLR_Events::WPSOLR_ACTION_POSTS_RESULTS,’ search_filter’, 99, 5);
function search_filter($query) {
// Frontend search only
if ( ! is_admin() ) {
//custom field check
$meta_query = array(
array(
‘key’ => ‘_show’,
‘value’ => ‘YES’,
‘compare’ => ‘==’,
)
);
$query->set(‘meta_query’, $meta_query);
}
return $query;
}prakashreddy.imduriParticipant8 months, 2 weeks ago #31069Adding this has added filter in frontend with acf field, with Yes prechecked, we dont need any filter in front end, we wanted to exclude indexing of product based on ACF field value if its set to NO.
wpsolrKeymaster8 months, 2 weeks ago #31072To exclude some posts from the index, you could modify the SQL query as described on https://www.wpsolr.com/forums/topic/hide-products-with-empty-or-zero-price/
prakashreddy.imduriParticipant7 months, 3 weeks ago #31286
Can’t we use this to hide products based on Value ‘NO’, regardless of if the same field exists with Yes, empty or even doesn’t exists for other posts ? Currently we have to use preselect Yes or No, for this to work, I want to hide those with No…prakashreddy.imduriParticipant7 months, 3 weeks ago #31292Can we create a custom field, and push data to that field, while indexing and use that to hide or show results. I want to set a create a field, if that meta_key isn’t available for a post id, and set the value to Yes.
We have ACF meta_key , which is either es, No or its not available for 80% of posts, when meta_key is not present, I want to create field and set to Yes.
Some sort of this code ?
$doc2->setField(‘id’, 124);
$doc2->setField(‘name’, ‘testdoc-2’);prakashreddy.imduriParticipant7 months, 3 weeks ago #31294we have around 2L posts, so this wont work for us.
wpsolrKeymaster7 months, 3 weeks ago #31295To exclude some posts from the index, you could modify the SQL query as described on https://www.wpsolr.com/forums/topic/hide-products-with-empty-or-zero-price/
You must be logged in to reply to this topic.