Forums Forums Search & Filter Pro Relation OR in filter

Viewing 4 posts - 1 through 4 (of 4 total)
  • Anonymous
    #242232

    Hi there,
    we would like to add a reltion OR about two field.
    We can’t set it in admin panel so we try to integrate it by php.
    In function.php we add this:

    function filter_results( $query_args, $sfid ) {
    	if($sfid==3981) {
    	$query_args = array(
    	    "meta_query" => array(
                        'relation' => 'OR',
                        array(
                            'key' => 'immobile_disponibile',
                            'compare' => 'NOT EXISTS',
                        ),
                        array(
                            'key' => 'immobile_disponibile',
                            'value' => '1',
                            'compare' => 'NOT LIKE',
                        ),
                    ),
    		"meta_key" => "immobile_disponibile",
    		'orderby' => 'menu_order',
    		"order" => "ASC",
                 );	
    	}
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_results', 20, 2 );

    But… not work.

    Trevor
    #242240

    I am not sure you can use that filter in this way to set OR between just two fields. Are you able to send me a live link/URL to your search page so I can take a look?

    Anonymous
    #242302

    I use “OR relation” in WP loop on https://www.houseandtrade.com/
    For example I use on this page https://www.houseandtrade.com/agenzia-immobiliare-lugano-ticino/case-ville/

    I would like to add the “OR relation” in the filter…

    There is a custom field (immobile_disponibile) with three value: 0, 1 and null.
    In WP loop, I show only post with value 0 or null.

    I need the same result in the filter…
    In this moment, the filter working without “OR relation” because, if add it, the filter not show any result.

    Trevor
    #242306

    I think you would need to code this into our query using this filter:

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    It takes the same structure of arguments as wp_query().

Viewing 4 posts - 1 through 4 (of 4 total)