Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operator added to the widget #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions core.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ function request( $request ) {
if ( !isset( $_GET['qmt'] ) )
return $request;

$operator = strtoupper( $_GET['qmt_operator'] );

foreach ( $_GET['qmt'] as $taxonomy => $terms ) {

$request['tax_query'][] = array(
'taxonomy' => $taxonomy,
'terms' => $terms,
'field' => 'term_id',
'operator' => 'IN'
'operator' => $operator
);
}

Expand Down Expand Up @@ -230,7 +233,7 @@ function qmt_get_query( $taxname = '' ) {
global $wp_query;

$qmt_query = array();

if ( !is_null( $wp_query->tax_query ) ) {
foreach ( $wp_query->tax_query->queries as &$tax_query ) {
$terms = _qmt_get_term_slugs( $tax_query );
Expand Down
3 changes: 2 additions & 1 deletion templates/checkboxes.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<form method="get" action="{{base-url}}" class="taxonomy-drilldown-checkboxes">
{{#taxonomy}}
<input type="hidden" name="qmt_operator" value="{{operator}}" />
{{#taxonomy}}
<div id="terms-{{taxonomy}}">
<h4>{{title}}</h4>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion templates/lists.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="taxonomy-drilldown-lists">
<div class="taxonomy-drilldown-lists">
{{#taxonomy}}
<div id="terms-{{taxonomy}}">
<h4>
Expand Down
8 changes: 7 additions & 1 deletion walkers.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ function specific_data( $term, $depth ) {
class QMT_Checkboxes_Walker extends QMT_Walker {

protected function set_selected_terms() {
$this->selected_terms = explode( ',', qmt_get_query( $this->taxonomy ) );

$terms = qmt_get_query( $this->taxonomy );
if ( strpos( $terms, '+' ) > 0 )
$this->selected_terms = explode( '+', $terms );
else
$this->selected_terms = explode( ',', $terms );

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not proud of these lines, since I think it can be written much better.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, what's stopping you? :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sunny days and lot of work! :P, but I'll improve it :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't argue with sunny days. ☀️

}

function specific_data( $term, $depth ) {
Expand Down
3 changes: 3 additions & 0 deletions widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

<p>{{{mode-input}}}</p>

<p>{{{operator-input}}}</p>


<p>{{{taxonomies-label}}}</p>

<ul class="qmt-taxonomies">
Expand Down
20 changes: 17 additions & 3 deletions widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Taxonomy_Drill_Down_Widget extends scbWidget {
'title' => '',
'mode' => 'lists',
'taxonomies' => array(),
'operator' => ''
);

static function init( $file ) {
Expand Down Expand Up @@ -77,13 +78,25 @@ function form( $instance ) {
'dropdowns' => __( 'dropdowns', 'query-multiple-taxonomies' ),
),
'text' => false,
'desc' => __( 'Mode:', 'query-multiple-taxonomies' ),
'desc' => __( 'Mode1:', 'query-multiple-taxonomies' ),
'extra' => array( 'class' => 'widefat' )
), $instance ),
'operator-input' => $this->input( array(
'type' => 'select',
'name' => 'operator',
'values' => array(
'AND' => __( 'And', 'query-multiple-taxonomies' ),
'IN' => __( 'Or', 'query-multiple-taxonomies' )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

),
'text' => false,
'desc' => __( 'Operator:', 'query-multiple-taxonomies' ),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Operator: seems vague; it should either be Operator between terms: or Operator between taxonomies:.

'extra' => array( 'class' => 'widefat' )
), $instance ),

'taxonomies-label' => __( 'Taxonomies:', 'query-multiple-taxonomies' )
);


$selected_taxonomies = $instance['taxonomies'];

// Start with the selected taxonomies
Expand Down Expand Up @@ -119,7 +132,7 @@ function form( $instance ) {

function content( $instance ) {
extract( $instance );

$taxonomies = array_filter( $taxonomies, array( __CLASS__, 'test_tax' ) );

$query = qmt_get_query();
Expand All @@ -132,7 +145,7 @@ function content( $instance ) {
} else {
echo call_user_func( array( __CLASS__, "generate_$mode" ), $taxonomies, array(
'reset-text' => __( 'Reset', 'query-multiple-taxonomies' ),
'reset-url' => QMT_URL::get(),
'reset-url' => QMT_URL::get(),'operator'=>$operator
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One key => value pair per line, please.

) );
}
}
Expand Down Expand Up @@ -204,6 +217,7 @@ private function generate_dropdowns( $taxonomies, $data ) {
}

private function generate_checkboxes( $taxonomies, $data ) {

$data = array_merge( $data, array(
'base-url' => QMT_URL::get_base(),
'submit-text' => __( 'Submit', 'query-multiple-taxonomies' ),
Expand Down