Displaying two CPTs in Custom Taxonomy Term
- This topic has 11 replies, 2 voices, and was last updated 3 years, 11 months ago by
webdevtrust GmbH.
-
AuthorPosts
-
May 20, 2021 at 10:45 PM #28329
webdevtrust GmbH
ParticipantHi 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
May 21, 2021 at 12:57 PM #28345Long Nguyen
ModeratorHi 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-loopTo 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 %}
May 21, 2021 at 5:06 PM #28359webdevtrust GmbH
ParticipantThank you, Long. I am having trouble targeting the single composer term page with the view-settings. How would I render the view there?
May 22, 2021 at 12:39 PM #28372Long Nguyen
ModeratorHi Chris,
You can set the Type: Archive, Location: TaxonomyName (Composer) Archive, specific for a term (johann-sebastian-bach). Screenshot https://share.getcloudapp.com/eDuyWymJ
May 23, 2021 at 8:40 PM #28384webdevtrust GmbH
ParticipantThank 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.
May 24, 2021 at 5:46 PM #28388Long Nguyen
ModeratorHi,
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 ) %} ...
May 24, 2021 at 8:10 PM #28392webdevtrust GmbH
Participantdefine( '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?
May 25, 2021 at 11:11 AM #28400Long Nguyen
ModeratorHi,
Please share your site credentials via this contact form https://metabox.io/contact/. I will help you to check the issue.
May 26, 2021 at 2:22 PM #28429webdevtrust GmbH
ParticipantI did, Long. Could you access the Website?
May 26, 2021 at 5:30 PM #28430Long Nguyen
ModeratorHi 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.
May 26, 2021 at 7:10 PM #28433webdevtrust GmbH
ParticipantThank you, Long! I'm glad that it's not just me being stupid.
June 2, 2021 at 2:14 PM #28616webdevtrust GmbH
ParticipantHi Long, any news on this from the development team?
-
AuthorPosts
- You must be logged in to reply to this topic.