epl_is_listing_results_page: is this page showing listing results?

Description #

epl_is_listing_results_page() returns true when the page WordPress is showing is a page of listings: an EPL search, a listing type archive such as /property/, a location, feature or business category archive, or any other archive whose listings are EPL listings. The [listing_results] shortcode uses it to decide whether to show the page's listings.

It reads the page WordPress is showing (the main query), not the current post, so it still works inside page builder templates. Elementor, for example, switches the current post to its template while it renders.

The epl_is_listing_results_page filter lets you change the answer, for example to treat your own taxonomy archive as listing results.


Usage #

if ( epl_is_listing_results_page() ) {
	// This page shows listings.
}

add_filter( 'epl_is_listing_results_page', 'my_is_listing_results_page' );

Parameters #

The function takes no parameters and returns a boolean.

The filter receives:

$is_results (bool)
True on EPL searches and listing archives, as worked out above.


Examples #

Treat an archive of your own listing_region taxonomy as listing results, so [listing_results] shows its listings.

function my_is_listing_results_page( $is_results ) {
	if ( is_tax( 'listing_region' ) ) {
		return true;
	}
	return $is_results;
}
add_filter( 'epl_is_listing_results_page', 'my_is_listing_results_page' );

Only return true on pages whose main query holds listings: [listing_results] shows whatever the main query found.


Notes #

  • It is also true when the current post is an EPL listing, such as on a single listing page.
  • Check it after WordPress has run the main query (from the wp action onwards, or in a template or shortcode). Earlier, the answer is always false.


Source #

lib/shortcodes/shortcode-listing-results.php, in epl_is_listing_results_page(). Since 3.6.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.