Enhance MB Views location conditions

Support MB Views Enhance MB Views location conditionsResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #43010
    RoderickRoderick
    Participant

    Hi,

    I have a question about the MB Views location conditions. I have made a view that I wish to add to categorie archives, but not to child-categories. Is there a way to do this without having to add location conditions manually per category?

    So as example:

    Categories list
    - New York (add MB View here)
    -- Activities (don't add here)
    -- Food (don't add here)

    Hope my question is clear and you have a solution.

    Best regards,
    Roderick

    #43021
    PeterPeter
    Moderator

    Hello,

    You can use the view Type: Code then add the conditional tag to the Code area to check if it is the parent term. For example:

    Add this code to the file functions.php in the theme/child theme folder

    function check_parent_category() {
        $current_term_id = get_queried_object_id();
        $check_term = get_term( $current_term_id );
        if ( $check_term->parent == 0 ) return true; // parent term - display the view template
    
        return false; // child term
    }

    then add the function name check_parent_category() to the Code area. Screenshot https://imgur.com/407g1Uw

    Refer to the documentation
    https://developer.wordpress.org/reference/classes/wp_term/
    https://docs.metabox.io/extensions/mb-views/#type

    #43035
    RoderickRoderick
    Participant

    Hello Peter,

    This is great! Thank you so much for the help 🙂 I will give this a try.

    Best regards,
    Roderick

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.