Hello ,
I am using above code into function.php file.
When I am filtering this for one custom fields , its working fine.
This is the code that working okay …
if ( ($asProfessionLength>0)){
$args[‘meta_key’] = ‘user_registration_radio_user_type’;
$args[‘meta_value’] = $asProfession;
$args[‘meta_compare’] = ‘LIKE’;
if( isset( $args[‘asProfession’] ) ) unset($args[‘asProfession’]);
return $args;
}
======> Now My concern is this when I am using filter on two custom fields using AND login , why its not giving any result.
….. This code is returning no data
I am using this code in same function in behalf of length of input fields data .
Please let me know whats wrong in this logic .
if($asCityLength>0 && $asProfessionLength>0){
$args[‘meta_query’] = array(
‘relation’ => ‘AND’,
array(
‘key’ => ‘user_registration_radio_user_type’,
‘value’ => ‘Lawyer’,
‘compare’ => ‘LIKE’,
‘type’ => ‘CHAR’,
),
array(
‘key’ => ‘user_registration_city’,
‘value’ => ‘Delhi’,
‘compare’ => ‘LIKE’,
‘type’ => ‘CHAR’,
)
);
return $args;
}
========>
This is the whole function , Please check where I am doing wrong…
function kia_meta_search( $args ){
// This $_GET is the name field of the custom input in search-author.php.
$search = ( isset($_GET[‘as’]) ) ? sanitize_text_field($_GET[‘as’]) : false ;
$asProfession = ( isset($_GET[‘asProfession’]) ) ? sanitize_text_field($_GET[‘asProfession’]) : false ;
$asCity = ( isset($_GET[‘asCity’]) ) ? sanitize_text_field($_GET[‘asCity’]) : false ;
$searchLength = strlen($search);
$asProfessionLength = strlen($asProfession);
$asCityLength = strlen($asCity);
if ( ($searchLength >0)){
$args[‘meta_key’] = ‘first_name’;
$args[‘meta_value’] = $search;
$args[‘meta_compare’] = ‘LIKE’;
if( isset( $args[‘search’] ) ) unset($args[‘search’]);
return $args;
}
if($asCityLength>0 && $asProfessionLength>0){
echo “Hello”;
$args[‘meta_query’] = array(
‘relation’ => ‘AND’,
array(
‘key’ => ‘user_registration_radio_user_type’,
‘value’ => ‘Lawyer’,
‘compare’ => ‘LIKE’,
‘type’ => ‘CHAR’,
),
array(
‘key’ => ‘user_registration_city’,
‘value’ => ‘Delhi’,
‘compare’ => ‘LIKE’,
‘type’ => ‘CHAR’,
)
);
return $args;
} else {
if ( ($asProfessionLength>0)){
$args[‘meta_key’] = ‘user_registration_radio_user_type’;
$args[‘meta_value’] = $asProfession;
$args[‘meta_compare’] = ‘LIKE’;
if( isset( $args[‘asProfession’] ) ) unset($args[‘asProfession’]);
return $args;
}
if ( ($asCityLength>0)){
$args[‘meta_key’] = ‘user_registration_city’;
$args[‘meta_value’] = $asCity;
$args[‘meta_compare’] = ‘LIKE’;
if( isset( $args[‘asCity’] ) ) unset($args[‘asCity’]);
return $args;
}
}
if($asCityLength ==0 && $asProfessionLength==0 && $searchLength==0){
$args[‘meta_key’] = ”;
$args[‘meta_value’] = ”;
$args[‘meta_compare’] = ”;
return $args;
}
}
add_filter(‘sul_user_query_args’, ‘kia_meta_search’);
Please help , I stuck here from so many days.