Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 7 additions & 4 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 @@ -226,11 +229,11 @@ function is_multitax( $taxonomies = array() ) {
*
* @return array( taxonomy => query )
*/
function qmt_get_query( $taxname = '' ) {
function qmt_get_query( $taxname = '', $glue = '+' ) {
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 All @@ -243,7 +246,7 @@ function qmt_get_query( $taxname = '' ) {
}

foreach ( $qmt_query as &$value )
$value = implode( '+', $value );
$value = implode( $glue, $value );
}

if ( $taxname ) {
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
6 changes: 5 additions & 1 deletion walkers.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ 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, ',');

$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
5 changes: 5 additions & 0 deletions widget.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@


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

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

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


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

<ul class="qmt-taxonomies">
Expand Down
32 changes: 29 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 @@ -51,6 +52,17 @@ function add_script() {
$(this).sortable();
$(this).disableSelection();
});

$('#qmt_types').change(function(){
console.log($('#qmt_types').val());
Copy link
Owner

Choose a reason for hiding this comment

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

This shouldn't be part of the PR.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I just uploaded this changes so you can check the code. But don't pay attention to that.

if ( $('#qmt_types').val() != 'checkboxes' )
$('.operator').parent().hide();
else{
$('.operator').parent().show();
}

});

});
</script>
<?php
Expand All @@ -65,7 +77,7 @@ function form( $instance ) {
'name' => 'title',
'type' => 'text',
'desc' => __( 'Title:', 'query-multiple-taxonomies' ),
'extra' => array( 'class' => 'widefat' )
'extra' => array( 'class' => 'widefat', 'id'=>'prueba' )
Copy link
Owner

Choose a reason for hiding this comment

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

What's prueba?

Copy link
Author

Choose a reason for hiding this comment

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

Don't pay attention to that, I'll remove. Was just a testing.

), $instance ),

'mode-input' => $this->input( array(
Expand All @@ -78,12 +90,24 @@ function form( $instance ) {
),
'text' => false,
'desc' => __( 'Mode:', 'query-multiple-taxonomies' ),
'extra' => array( 'class' => 'widefat' )
'extra' => array( 'class' => 'widefat types', 'id'=>'qmt_types' )
Copy link
Owner

Choose a reason for hiding this comment

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

Using IDs isn't a good idea because you can have multiple widgets on the screen (in the same sidebar or in different sidebars).

Copy link
Author

Choose a reason for hiding this comment

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

Yes, the first approach was using a class, but I had some issues so I tried with the id. But I'll change that.

), $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 between terms:', 'query-multiple-taxonomies' ),
'extra' => array( 'class' => 'widefat operator' )
), $instance ),

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


$selected_taxonomies = $instance['taxonomies'];

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

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

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

$query = qmt_get_query();
Expand All @@ -133,6 +157,7 @@ function content( $instance ) {
echo call_user_func( array( __CLASS__, "generate_$mode" ), $taxonomies, array(
'reset-text' => __( 'Reset', 'query-multiple-taxonomies' ),
'reset-url' => QMT_URL::get(),
'operator'=>$operator
) );
}
}
Expand Down Expand Up @@ -204,6 +229,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