Skip to content

Commit

Permalink
Add the trait to process the taxonomies.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwelcher committed Oct 7, 2024
1 parent 0f0ef1d commit fb95d64
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions includes/Query_Params_Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Query_Params_Generator {
use Traits\Include_Posts;
use Traits\Meta_Query;
use Traits\Date_Query;
use Traits\Exclude_Taxonomies;


/**
Expand All @@ -28,6 +29,7 @@ class Query_Params_Generator {
'include_posts',
'meta_query',
'date_query',
'exclude_taxonomies'
);

/**
Expand Down
30 changes: 30 additions & 0 deletions includes/Traits/Exclude_Taxonomies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Exclude_Taxonomies
*/

namespace AdvancedQueryLoop\Traits;

/**
* Trait
*/
trait Exclude_Taxonomies {

/**
* Main processing function.
*/
public function process_exclude_taxonomies(): void {
$taxonomies_to_exclude = $this->custom_params['exclude_taxonomies'];
if( count( $taxonomies_to_exclude ) ) {
$tax_query = [];
foreach ( $taxonomies_to_exclude as $slug ) {
$tax_query[] = [
'taxonomy' => $slug,
'operator' => 'NOT EXISTS'
];
}
$this->custom_args['tax_query'] = $tax_query;
}
}
}

6 changes: 3 additions & 3 deletions src/components/exclude-taxonomies.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const ExcludeTaxonomies = ( { attributes, setAttributes } ) => {
query: {
multiple_posts: multiplePosts = [],
postType,
excluded_taxonomies: excludedTaxonomies = [],
exclude_taxonomies: excludeTaxonomies = [],
} = {},
} = attributes;

Expand All @@ -64,7 +64,7 @@ export const ExcludeTaxonomies = ( { attributes, setAttributes } ) => {
label={ __( 'Exclude Taxonomies', 'advanced-query-loop' ) }
value={
prepDataFromTokenField(
excludedTaxonomies,
excludeTaxonomies,
taxonomies,
'slug',
'name'
Expand All @@ -75,7 +75,7 @@ export const ExcludeTaxonomies = ( { attributes, setAttributes } ) => {
setAttributes( {
query: {
...attributes.query,
excluded_taxonomies:
exclude_taxonomies:
prepDataFromTokenField(
selectedTaxonomies,
taxonomies,
Expand Down

0 comments on commit fb95d64

Please sign in to comment.