Skip to content

Instantly share code, notes, and snippets.

@Jehu
Created August 21, 2023 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jehu/9ddbc4a39a3534fab72926456d8ddc79 to your computer and use it in GitHub Desktop.
Save Jehu/9ddbc4a39a3534fab72926456d8ddc79 to your computer and use it in GitHub Desktop.
filter Bricks term query for custom taxonomy tag
<?php
// Include only terms where posts do have a term from custom 'hersteller' taxonomy
add_filter(
"bricks/terms/query_vars",
function ($query_vars, $settings, $element_id) {
if ($element_id !== "qaajzi") {
return $query_vars;
}
$hersteller_ids = [];
$term_id = get_queried_object_id();
$args = [
"post_type" => "produkt",
"post_status" => "publish",
"tax_query" => [
[
"taxonomy" => "category",
"field" => "term_id",
"terms" => $term_id,
]
]
];
$my_query = new WP_Query($args);
if ( $my_query->get_posts() ) {
foreach($my_query->get_posts() as $post) {
$hersteller = array_shift(wp_get_post_terms($post->ID, 'hersteller'));
if($hersteller->term_id) {
$hersteller_ids[$hersteller->term_id] = $hersteller->name;
}
}
}
wp_reset_postdata();
$query_vars["include"] = array_keys($hersteller_ids);
return $query_vars;
},
10,
3
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment