Is this possible?
I have a global taxonomy ‘brands’, I have set up for products cpt and resources cpt.
On a page, I want to show all brands that have posts from the resources cpt.
I tried with a query loop, and nested another but couldn’t figure it out.
I need this because, some brands have products but not resources and vice-versa
Got it with query editor:
Claude for the rescue!
// Get all wpdmpro post IDs first
$wpdmpro_posts = get_posts([
'post_type' => 'wpdmpro',
'numberposts' => -1,
'fields' => 'ids'
]);
// If no wpdmpro posts exist, return empty result
if (empty($wpdmpro_posts)) {
return [
'taxonomy' => 'marca',
'include' => [0], // This will return no terms
];
}
// Return query for marca terms that have wpdmpro posts
return [
'taxonomy' => 'marca',
'hide_empty' => true,
'object_ids' => $wpdmpro_posts
];