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

Reply To: limit search

#39636
Ernest MarcinkoErnest Marcinko
Keymaster

Hi Tommy,

Oh, then it was the custom code causing the issue as I predicted earlier. Changing the logic to an OR basically negated every other criteria for the search query. One last thing to try is to inject the post type and post status queries to the first code:

add_filter('asp_query_cpt', 'asp_change_query_directly', 10, 1);
function asp_change_query_directly($q) {
	global $wpdb;
	$q = preg_replace('/AND ' . preg_quote("$wpdb->posts.post_parent IN ") . '\((.*?)\)/im',
		"OR ($wpdb->posts.post_type IN ('post', 'page', 'dealer') AND $wpdb->posts.post_status LIKE 'publish' AND $wpdb->posts.post_parent IN($1))",
		$q);
	return $q;
}

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);
			$args['post_meta_filter'][] = array(
				'key'     => 'ad_location', 
				'value'   => array('62b9acbc2709e', '123', 'ABC'),
				'operator' => 'ELIKE',
				'allow_missing' => false  
			);
		}

	return $args;
}

Unfortunately I am too busy to do do custom jobs, I am sorry.