Skip to content

Commit

Permalink
fixed hierarchy inside select; added 'match' behavior;
Browse files Browse the repository at this point in the history
  • Loading branch information
franz-josef-kaiser committed Jan 30, 2013
1 parent ad395cb commit cfc5656
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
26 changes: 20 additions & 6 deletions inc/base.abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,31 @@ public function __construct()

public function setup_vars()
{
! isset( $this->post_type ) AND $this->post_type = get_current_screen()->post_type;
! isset( $this->taxonomies ) AND $this->taxonomies = array_diff(
! isset( $this->post_type ) AND $this->post_type = get_current_screen()->post_type;
! isset( $this->taxonomies ) AND $this->taxonomies = array_diff(
get_object_taxonomies( $this->post_type )
,get_taxonomies( array(
'show_admin_column' => false
) )
);
! isset( $this->post_status ) AND $this->post_status = get_post_stati( array(
'show_in_admin_status_list' => true
,'show_in_admin_all_list' => true
) );
if ( ! isset( $this->post_status ) )
{
$args = array(
'private' => false
,'internal' => false
,'exclude_from_search' => false
,'show_in_admin_all_list' => true
,'show_in_admin_status_list' => true
);
current_user_can(
get_post_type_object( $this->post_type )
->cap
->read_private_posts
)
AND $args['private'] = true;

$this->post_status = get_post_stati( $args );
}
}

abstract function setup_actions();
Expand Down
10 changes: 8 additions & 2 deletions inc/filter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,20 @@ public function get_markup()
? selected( $term->slug, $_GET[ $tax ], false )
: ''
;
$parent = '0' !== $term->parent ?: true;
$parent = false;
if (
0 >= absint( $term->parent )
OR ! is_taxonomy_hierarchical( $tax )
)
$parent = true;

$options .= sprintf(
'<option class="level-%s" value="%s" %s>%s%s</option>'
,! $parent ? '1' : '0'
,$term->slug
,$selected
,! $parent ? str_repeat( '&nbsp;', 3 ) : ''
,"{$term->name} ({$term->count})"
,"{$term->name} <sup>({$term->count})</sup>"
);
}
$html .= sprintf(
Expand Down
23 changes: 7 additions & 16 deletions inc/match.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function init()

public function setup_actions()
{
add_filter( 'posts_where' , array( $this, 'set_where' ) );
add_filter( 'pre_get_posts', array( $this, 'tax_filter' ) );
}

public function get_markup()
Expand All @@ -32,23 +32,14 @@ public function get_markup()
return print "{$html} &nbsp;";
}

public function set_where( $where )
public function tax_filter( &$query )
{
global $wpdb;
$tt_ids = $this->get_tax_ids();
if ( empty( $tt_ids ) )
return $where;
$where .= $wpdb->prepare(
" AND ID IN (
SELECT object_id
FROM {$wpdb->term_relationships}
WHERE term_taxonomy_id
IN (%d)
)"
,join( ",", $tt_ids )
property_exists( $query->tax_query, 'queries' ) AND $tax_query = array_merge(
$query->tax_query->queries
,array( 'relation' => 'OR' )
);

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

# ====== HELPER
Expand Down

0 comments on commit cfc5656

Please sign in to comment.