get_property_meta

Description #

Returns the saved value of any listing field (meta key), such as property_bedrooms, property_price or property_address_suburb. It is the main way to read a listing's data in a template, add-on or snippet.

It reads from the global $property object, which Easy Property Listings sets up for you on single listings, archive pages, shortcodes and widgets.


Usage #

global $property;
$value = $property->get_property_meta( $meta_key, $allowzero );

Two shortcuts do the same thing for the current listing:

  • get_property_meta( $meta_key ): returns the value.
  • the_property_meta( $meta_key ): prints the value.

Parameters #

$meta_key (string) (required)
The field to read. See the custom fields lists for each listing type: Property, Rural, Land, Commercial, Commercial Land, Business.

$allowzero (bool) (optional, default true)
Set to false to get an empty value instead of 0, so "0 bathrooms" isn't shown. Only use false on number fields. With false, any value that isn't a number (for example a category of "House") also comes back empty.


Return #

  • The saved value: usually a string or number.
  • An array for file fields (for example floor plans) and other fields saved as arrays.
  • null when the listing has no value for that field.

Yes/no fields (property_price_display, property_rent_display, property_under_offer, property_address_display, property_com_display_suburb, property_featured) are always returned in lowercase (yes / no), even when a feed saved YES.


Filters #

epl_meta_filter_{$meta_key}: change the value of one field everywhere it is read.

add_filter( 'epl_meta_filter_property_bedrooms', function ( $value ) {
	return $value ? $value : 'Studio';
} );

Examples #

Number of bedrooms, hiding 0

global $property;
$bedrooms = $property->get_property_meta( 'property_bedrooms', false );

Print a field in a template

<p>Land: <?php the_property_meta( 'property_land_area' ); ?></p>

Several fields at once

function my_output_several_custom_values() {
	global $property;
	$meta_keys = array( 'property_bedrooms', 'property_bathrooms', 'property_shed' );
	foreach ( $meta_keys as $meta_key ) {
		echo esc_html( $meta_key . ' => ' . $property->get_property_meta( $meta_key, false ) ) . '<br>';
	}
}
property_bedrooms => 4
property_bathrooms => 2
property_shed => 1

Use a rule when there is one #

For questions about the price and address, ask the rule instead of reading the field. The rules also check the status, the settings and any filters, so your output matches the rest of the site:

  • Under offer? $property->is_under_offer(), not property_under_offer. See Price rules.
  • Show the street address? $property->show_street_address(), not property_address_display. See Address rules.
  • Has a floor plan, video or inspection times? See Conditional tags.

Changelog #

  • 2.0 Introduced.
  • 3.5.22 Yes/no fields returned in lowercase.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.