This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: limit search

#39540
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

Thank you very much for your kind words!

It should not be too difficult, something like this:

add_filter( 'asp_query_args', 'asp_include_only_parent_ids', 10, 2 );
function asp_include_only_parent_ids( $args, $id ) {

	if ( $id == 3 ) {
		$args['post_parent'] = array(11748);
	} else if ( $id == 12 ) {
		$args['post_parent'] = array(3239);
	}
	
	$args['post_meta_filter'][] = array(
		'key'     => 'customfield', // meta key
		'value'   => 'abc'
		'operator' => 'LIKE',	   // You can also try ELIKE here for more strict match
		'allow_missing' => false   // allow match if this custom field is unset
	);

	return $args;
}

You may need to try the “ELIKE” operator as well to have an exact field match, as well as try the “allow_missing” argument on true if you want results where this field does not exist.

I hope this helps!