easypropertylistings / Easy-Property-Listings

Easy Property Listings is ready to make your real estate website faster, safer and better!
GNU General Public License v2.0
78 stars 60 forks source link

3.5 - Helper function to get the label from a value meta key. #1034

Closed mervb closed 1 year ago

mervb commented 1 year ago

Currently we have helper functions to get the Label eg Current, Sold Leased from the saved value of current sold leased

/**
 * Test function to display the category
 *
 * @return void 
 */
function some_function() {
    global $property;

    $category = $property->get_property_meta( 'property_category' );

    $label = epl_listing_meta_property_category_value( $category );

    echo '<br>' . $label;
}
add_action( 'epl_property_price', 'some_function' );

If would be handy to have a helper function that we could pass the meta key and get the label

like get_property_meta_label( 'property_category' )

example

function epl_maybe_get_meta_label( $meta_key ) {

        $value = get_property_meta( $meta_key );

        $function = 'epl_get_'.$meta_key.'_opts';

        if( function_exists( ) ) {

                $labels = $function();
                $value = isset( $labels[$value] ) ? $labels[$value] : $value;
        }

        return $value;
}
mervb commented 1 year ago

as we already have a public function

get_property_meta lets call this get_property_meta_label

mervb commented 1 year ago

added epl_get_property_meta_label function in 3.5