Skip to content

Commit

Permalink
added markup for button. added working filter of and custom taxonomie…
Browse files Browse the repository at this point in the history
…s. added where clause and abort statements. query string/clause still doesn't work.
  • Loading branch information
franz-josef-kaiser committed Jan 28, 2013
1 parent a3aedf0 commit 465b0fd
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions filterama.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public function __construct()
public function setup()
{
add_action( current_filter(), array( $this, 'setup_vars' ), 20 );
add_action( 'restrict_manage_posts', array( $this, 'get_markup' ) );
add_action( 'restrict_manage_posts', array( $this, 'get_markup_tax_select' ) );
add_filter( "manage_taxonomies_for_{$this->post_type}_columns", array( $this, 'add_columns' ) );

// ALL or ANY
# add_action( 'restrict_manage_posts', array( $this, 'all_or_any_markup' ) );
# add_filter( 'posts_where' , array( $this, 'all_or_any' ) );
add_action( 'restrict_manage_posts', array( $this, 'get_markup_match' ) );
add_filter( 'posts_where' , array( $this, 'sql_match' ) );
}

public function setup_vars()
Expand All @@ -67,7 +67,7 @@ public function add_columns( $taxonomies )
* Select form elements, used to filter the post list
* @return string HTML
*/
public function get_markup()
public function get_markup_tax_select()
{
$html = '';
foreach ( $this->taxonomies as $tax )
Expand Down Expand Up @@ -108,35 +108,59 @@ public function get_markup()
* MarkUp for the "ALL or ANY" match select
* @return string $html HTML
*/
public function all_or_any_markup()
public function get_markup_match()
{
$html = '';
return $html;
$html = get_submit_button(
__( 'Match', 'filterarma_textdomain' )
,'secondary'
,'match'
,false
);
return print "{$html}  ";
}

/**
* Intercept filter behavior to match ANY or ALL selected terms
* @param string $match WHERE SQL clause
* @param string $where WHERE SQL clause
* @return string SQL
*/
public function all_or_any( $match )
public function sql_match( $where )
{
global $wpdb;
$param = 'match_all';
$param = 'match';
$taxonomies = array_filter( array_intersect_key(
$_GET
,array_flip( $this->taxonomies )
) );
if (
isset( $_GET[ $param ] )
AND ! empty( $_GET[ $param ] )
)
$match .= $wpdb->prepare(
AND ! empty( $taxonomies )
)
{
// Get set taxonomy terms
// Get IDs
$tt_ids = array();
foreach ( $taxonomies as $tax => $term_slug )
$tt_ids[] = term_exists( $term_slug, $tax );
// Nothing to do here
if ( empty( $tt_ids ) )
return $where;

$tt_ids = wp_list_pluck( $tt_ids, 'term_taxonomy_id' );

// Append to query string
$where .= $wpdb->prepare(
" AND ID IN (
SELECT object_id
FROM {$wpdb->term_relationships}
WHERE term_taxonomy_id
IN (%s)
)"
,implode( ",", $_GET[ $param ] )
,implode( ",", $tt_ids )
);
}

return $match;
return $where;
}
}

0 comments on commit 465b0fd

Please sign in to comment.