a_z_listing_cache( array|string|WP_Query|A_Z_Listing $query = null, string $type = '', 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


(string) (Optional) The type of items displayed in the listing: 'terms' or 'posts'.

Default value: ''


(bool) (Optional) Try to use a caching plugin. See <a href="https://a-z-listing.com/">https://a-z-listing.com/</a> for the caching plugin we created to work with this feature.

Default value: true


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


File: functions/helpers.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 ];

More Information

You are currently logged out. To view tickets you must first login.

I have read and understood the Terms of Service

User Contributed Notes

Leave a Reply

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