Skip to content

Commit

Permalink
shortened markup
Browse files Browse the repository at this point in the history
added problem explanation to tax filter
updated tax filter
shortened abort conditions for tax ids
  • Loading branch information
franz-josef-kaiser committed Feb 1, 2013
1 parent b0c7375 commit 019e3d3
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions inc/match.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ final class WCMF_match extends WCMF_base
{
protected static $instance;

public $get_param = 'match';

public static function init()
{
null === self::$instance AND self::$instance = new self;
Expand All @@ -23,31 +25,49 @@ public function setup_actions()

public function get_markup()
{
$html = get_submit_button(
__( 'Match', 'filterama' )
,'secondary'
,'match'
,false
return printf(
'%s  '
,get_submit_button(
__( 'Match', 'filterama' )
,'secondary'
,$this->get_param
,false
)
);
return print "{$html}  ";
}

/**
* Attaches the `tax_query` query var to the $wp_query object.
* The "original" $tax_query property inside the $wp_query object
* is a reference to the `WP_Tax_Query` class and can not be used
* to set arguments for a tax query. Therefore the sub object has
* to be taken, transformed and then attached to the `query_vars`
* part of the $wp_query object. Else the `relation` argument
* gets unset, will not be used and the default is `AND`.
* @param object $query References to the current `$wp_query` object
* @return object $query
*/
public function tax_filter( &$query )
{
property_exists( $query->tax_query, 'queries' ) AND $tax_query = array_merge(
$query->tax_query->queries
,array( 'relation' => 'OR' )
);
$query->set( 'tax_query', $tax_query );
if (
! isset( $_GET[ $this->get_param ] )
OR ! $query->is_main_query()
)
return;

property_exists( $query->tax_query, 'queries' )
AND ! empty( $query->tax_query->queries )
AND $query->set( 'tax_query', array_merge(
$query->tax_query->queries
,array( 'relation' => 'OR' )
) );
return $query;
}

# ====== HELPER

public function get_tax_ids()
{
$param = 'match';

// Get set taxonomy terms
$taxonomies = array_filter( array_intersect_key(
$_GET
Expand All @@ -56,8 +76,7 @@ public function get_tax_ids()

$tt_ids = array();
if (
! isset( $_GET[ $param ] )
OR empty( $_GET[ $param ] )
! isset( $_GET[ $this->get_param ] )
OR empty( $taxonomies )
// Noting to match for a single tax
OR 1 >= count( $taxonomies )
Expand Down

0 comments on commit 019e3d3

Please sign in to comment.