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

Reply To: Conditional brackets – either/or possible?

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Conditional brackets – either/or possible? Reply To: Conditional brackets – either/or possible?

#42329
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

I’m afraid that is not possible via the bracket syntax.

You can however use the asp_results hook to modify the results fields with a bit of custom code. With that you can basically do anything you want to.

Something like this maybe:

add_filter( 'asp_results', 'asp_my_custom_field_code', 10, 1 );
function asp_my_custom_field_code( $results ) {
    // Field names
    $field1_key = 'field_1';
    $field2_key = 'field_2';

    foreach ($results as $k=>&$r) {
	// ACF support
        if ( function_exists('get_field') ) {
            $field1 = get_field( $field1_key, $r->id, true ); 
            $field2 = get_field( $field2_key, $r->id, true ); 
        } else {
            $field1 = get_post_meta( $r->id, $field1_key, true );
            $field2 = get_post_meta( $r->id, $field2_key, true );
	}

        // Change only, if the meta is specified
        if ( empty($field1) ) {
		if ( !empty($field2) ) {
			$r->content = $field2;
		}
        } else {
			$r->content = $field1;
		}
    }

    return $results;
}