Inventory_Presser_Taxonomies::maybe_exclude_sold_vehicles( WP_Query $query )

maybe_exclude_sold_vehicles


Description Description

Filter callback. Implements the "include sold vehicles" checkbox feature in vehicle archives and search results.


Top ↑

Parameters Parameters

$query

(WP_Query) (Required)


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class-taxonomies.php

	function maybe_exclude_sold_vehicles( $query )
	{
		if( is_admin() || ! $query->is_main_query()
			|| ! ( is_search() || is_post_type_archive( INVP::POST_TYPE ) ) )
		{
			return;
		}

		//if the checkbox to include sold vehicles is checked, abort
		$plugin_settings = INVP::settings();
		if( isset( $plugin_settings['include_sold_vehicles'] ) && $plugin_settings['include_sold_vehicles'] )
		{
			return;
		}

		$taxonomy = 'availability';

		//if there is already a tax_query for taxonomy availability, abort
		if( $query->is_tax( $taxonomy ) )
		{
			return;
		}

		//do this
		$tax_query = array(
			array(
				'taxonomy' => $taxonomy,
				'field'    => 'slug',
				'terms'    => 'sold',
				'operator' => 'NOT IN',
			)
		);

		$query->set( 'tax_query', $tax_query );
	}