Custom Fields
Re-Envisioned
Support MB Views Displaying two CPTs in Custom Taxonomy Term

  • Creator
    Topic
  • #28329
    Chris
    Participant

    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

Viewing 10 replies - 1 through 10 (of 11 total)
  • Author
    Replies
  • #28345
    Long Nguyen
    Moderator

    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 %}
    #28359
    Chris
    Participant

    Thank you, Long. I am having trouble targeting the single composer term page with the view-settings. How would I render the view there?

    #28372
    Long Nguyen
    Moderator

    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

    #28384
    Chris
    Participant

    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.

    #28388
    Long Nguyen
    Moderator

    Hi,

    It looks like the View settings box is broken. Please follow the step Debugging Information here https://metabox.io/support/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 ) %}
    ...
    #28392
    Chris
    Participant

    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?

    #28400
    Long Nguyen
    Moderator

    Hi,

    Please share your site credentials via this contact form https://metabox.io/contact/. I will help you to check the issue.

    #28429
    Chris
    Participant

    I did, Long. Could you access the Website?

    #28430
    Long Nguyen
    Moderator

    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.

    #28433
    Chris
    Participant

    Thank you, Long! I'm glad that it's not just me being stupid.

Viewing 10 replies - 1 through 10 (of 11 total)
  • You must be logged in to reply to this topic.