rep__extract_search_categories()
This function is used to retrieve the agency post ID associated with a listing or agent based on the provided post ID.
Namespace
REP_Malcolm
Parameters
$search_categories
array
Search categories.
$type
string
Type of info to extract from search categories
Return
array
List of listing states/categories extracted.
Source
File: \includes\rep-helper-functions.php
function rep__extract_search_categories( $search_categories, $type, $extract_all = false ){
$data = [];
if( is_array( $search_categories ) ){
foreach( $search_categories as $sc ){
if( is_string( $sc ) ){
$sc_arr = explode( " ", $sc );
if( $type == 'listing_category' ){
$category = lp__array_key_value( 0, $sc_arr );
if( $category && ! in_array( $category, $data ) ) $data[] = $category;
} elseif( $type == 'listing_state' ){
$state_1 = lp__array_key_value( 1, $sc_arr );
$state_2 = lp__array_key_value( 3, $sc_arr );
if( $state_1 && ! in_array( $state_1, $data ) ) $data[] = $state_1;
if( $state_2 && ! in_array( $state_2, $data ) ) $data[] = $state_2;
}
}
}
}
if( $extract_all && in_array( 'all', $data ) ){
unset( $data['all'] );
if( $type == 'listing_category' ){
$data = array_merge( $data, REP__Common::LISTING_CATEGORIES );
} elseif( $type == 'listing_state' ) {
$data = array_merge( $data, REP__Common::LISTING_STATES );
}
$data = array_values( array_unique( $data ) );
}
return $data;
}