Support Forum
Hi Long,
I've got a Custom Taxonomy (composer) for WooCommerce-Products and Events. The composer term is listing the assigned Product but not the 3 assigned Events with the Term although I can see them counted (Showing all 4 results). How could I achieve that the events are displayed as well? With MB Views?
Ref: https://akademie.webdevtrust.com/composer/johann-sebastian-bach/
Best regards
Hi Chris,
To get multiple post types for each term, you need to use the custom query.
$args = array(
'post_type' => array( 'product', 'event' ),
'tax_query' => array(
array(
'taxonomy' => 'composer',
'field' => 'slug',
'terms' => 'johann-sebastian-bach',
),
),
);
$query = new WP_Query( $args );
See more on this documentation
https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters
https://wordpress.stackexchange.com/questions/103368/query-multiple-custom-post-types-in-single-loop
To show post types in View, you can use the function get_posts() via proxy mb.
For example:
{% set args = { post_type: ['product', 'event'], tax_query: [ { taxonomy: 'composer', field: 'slug', terms: 'johann-sebastian-bach' } ] } %}
{% set my_posts = mb.get_posts( args ) %}
{% for post in my_posts %}
{{ post.post_title }}<br>
{% endfor %}
Thank you, Long. I am having trouble targeting the single composer term page with the view-settings. How would I render the view there?
Hi Chris,
You can set the Type: Archive, Location: TaxonomyName (Composer) Archive, specific for a term (johann-sebastian-bach). Screenshot https://share.getcloudapp.com/eDuyWymJ
Thank you for the screenshot, Long. My settings-page is looking different than yours (Screenshot https://drive.google.com/file/d/1gHL7PYRfP2rtGV9eg6WSYhGHTaeZwjza/view?usp=sharing). I do not have a category archive available for composers.
I need to display assigned events for every composer, not just a specific one (Ref: https://akademie.webdevtrust.com/composer/sebastian-kupfer/). I just can't figure out to inject anything there.
Hi,
It looks like the View settings box is broken. Please follow the step Debugging Information here https://support.metabox.io/topic/how-to-create-a-new-topic/ to troubleshoot this issue.
After it works, you can set the Type: Archive, Location: TaxonomyName (Composer) Archive, specific for a term: All and use this code for all terms of composer.
{% set args = { post_type: ['product', 'event'], tax_query: [ { taxonomy: 'composer', field: 'slug', terms: term.slug } ] } %}
{% set my_posts = mb.get_posts( args ) %}
...
define( 'WP_DEBUG', true ) is active but no errors or warnings are shown
Console does not display any JavaScript errors
With Storefront theme active and all plugins deactivated my Views settings box looks the same as before: https://drive.google.com/file/d/1gHL7PYRfP2rtGV9eg6WSYhGHTaeZwjza/view?usp=sharing
How do we go on from here, do you need access to the admin?
Hi,
Please share your site credentials via this contact form https://metabox.io/contact/. I will help you to check the issue.
I did, Long. Could you access the Website?
Hi Chris,
The Type and Location option of View needs the extension MB Conditional Logic enabled. Go to Meta Box > Extensions to enable it.
But after the selection works, I see that the View cannot override the template of the Product Category of WooCommerce. For other taxonomies of post types, it still works. I will inform the development team to check this case and get back to you later.
Thank you, Long! I'm glad that it's not just me being stupid.
Hi Long, any news on this from the development team?