a_z_listing_cache( array|string|WP_Query|A_Z_Listing $query = null, bool $use_cache = true )

Get a saved copy of the A_Z_Listing instance if we have one, or make a new one and save it for later




(array|string|WP_Query|A_Z_Listing) (Optional) a valid WordPress query or an A_Z_Listing instance

Default value: null


(bool) (Optional) use the plugin's in-built query cache

Default value: true


(A_Z_Listing) a new or previously-saved instance of A_Z_Listing using the provided construct_query


File: partials/class-a-z-listing.php

function a_z_listing_cache( $query = null ) {
	static $cache = array();

	// copy $query into $obj in case it already is a valid A_Z_Listing instance.
	$obj = $query;
	if ( $obj instanceof A_Z_Listing ) {
		// we received a valid A_Z_Listing instance so we get the query from it for the cache lookup/save key.
		$query = $obj->get_the_query();

	// check the cache and return any pre-existing A_Z_Listing instance we have.
	$key = wp_json_encode( $query );
	if ( array_key_exists( $key, $cache ) ) {
		return $cache[ $key ];

	// if $query is $obj then we did not get an A_Z_Listing instance as our argument, so we will make a new one.
	if ( $query === $obj ) {
		$obj = new A_Z_Listing( $query );
	// save the new A_Z_Listing instance into the cache.
	$cache[ $key ] = $obj;

	// return the new A_Z_Listing instance.
	return $cache[ $key ];

User Contributed Notes

You must log in before being able to contribute a note or feedback.

This site uses Akismet to reduce spam. Learn how your comment data is processed.