Conditional tags: listing types, pages, agents and "has" checks
Description #
Conditional tags answer yes/no questions about the page or listing, like WordPress's own is_single(). Use them in templates, add-ons and snippets to decide what to show. They live in lib/includes/conditional-tags.php.
Listing types #
These return lists of listing types (post types). Each has a filter so you can add your own type.
epl_get_core_post_types(): all seven built-in types: property, rental, land, rural, commercial, commercial_land, business. Filter:epl_core_post_types.epl_get_core_sales_post_types(): the types for sale (all except rental). Filter:epl_core_sales_post_types.epl_get_core_rental_post_types(): the types for rent (rental). Filter:epl_core_rental_post_types.epl_all_post_types(): the types switched on in Settings, plus any added by extensions. Filter:epl_additional_post_types.
// Query every active listing type. $listings = new WP_Query( array( 'post_type' => epl_all_post_types() ) );
Which page is this? #
Pass a post type to check that type, or leave it out to check the current post.
is_epl_post( $type ): is it any active listing type?is_epl_core_post( $type ): is it one of the seven built-in types?is_epl_sales_post( $type ): is it a type for sale?is_epl_rental_post( $type ): is it a rental?is_epl_post_type( $type ): is the current post this listing type? (The type is required.)is_epl_post_single(): are we on a single listing page?is_epl_post_archive(): are we on a listing archive page?
// Load a script only on single listing pages.
add_action( 'wp_enqueue_scripts', function () {
if ( is_epl_post_single() ) {
wp_enqueue_script( 'my-listing-script', get_stylesheet_directory_uri() . '/js/listing.js', array(), '1.0', true );
}
} );
// Show the bond only on rentals.
if ( is_epl_rental_post() ) {
echo esc_html( get_property_meta( 'property_bond' ) );
}
Agents #
These return the agent's WordPress user ID, or false when the listing has no agent there (or the username doesn't match a user). Use them in an if.
epl_listing_has_primary_agent()epl_listing_has_secondary_agent()(alsoepl_listing_has_secondary_author(), kept for older code)epl_listing_has_third_agent()epl_listing_has_fourth_agent()epl_listing_is_agent_available( $agent_key ): any agent field, for exampleproperty_second_agent.
$second_agent_id = epl_listing_has_secondary_agent();
if ( $second_agent_id ) {
echo esc_html( get_the_author_meta( 'display_name', $second_agent_id ) );
}
Does this listing have� (3.6) #
These check the current listing (global $property). Use them to skip an empty heading, tab or button wrapper. Each has a filter of the same name.
epl_listing_has_floor_plans(): a floor plan, using the same fields as the Floor Plan button (epl_floorplan_keysfilter).epl_listing_has_video(): a video URL.epl_listing_has_inspection_times(): upcoming inspection times. Past times don't count, and sold or leased listings have none.epl_listing_has_auction_date(): an auction date.epl_listing_has_links(): any of the single listing buttons: external links, floor plans, mini web, energy certificate or video. Buttons hidden with anepl_show_{$key}filter don't count.epl_listing_has_any_meta( $keys, $respect_show ): any of the fields in$keyshas a value. Set$respect_showto true to skip fields hidden with anepl_show_{$key}filter.
<?php if ( epl_listing_has_inspection_times() ) : ?> <h3>Inspections</h3> <?php do_action( 'epl_property_inspection_times' ); ?> <?php endif; ?> <?php if ( epl_listing_has_links() ) : ?> <div class="my-buttons"><?php do_action( 'epl_buttons_single_property' ); ?></div> <?php endif; ?>
Related #
- Price rules: is_under_offer(), has_advertised_price() and more.
- Address rules: show_street_address() and more.
- get_property_meta
- epl_get_option