1

I'm trying to adjust a function that checks if the site visitor is on a post type archive and returns a certain layout. I need it to also check to see if it is in certain categories (using regular WP categories - not custom taxonomies).

This is the original code that works.

// ADD ARCHIVE LAYOUT FOR POSITION VIDEOS POST TYPE
function custom_filter_positionvids_layout( $layout_id ) {
if ( is_post_type_archive('position_video') )
        return '58bef4ba370de';

return $layout_id;
}
add_filter( 'builder_filter_current_layout', 'custom_filter_positionvids_layout' );

Can I add some sort of && statement with category ID's so it will check if the page is displaying the post type archive and in a list of certain categories? This will help me give a different layout for protected member content.

1

You would just need to add your else if checks as needed. Category archives can be detected using is_tax( $taxonomy, $term ) or more specifically is_category( $term_id|$term_name ).

// ADD ARCHIVE LAYOUT FOR POSITION VIDEOS POST TYPE
function custom_filter_positionvids_layout( $layout_id ) {
    if ( is_post_type_archive( 'position_video' ) ) {
        return '58bef4ba370de';
    }

    if ( is_category( 'blog' ) ) {
        return '12345';
    }

    if ( is_category( 5 ) ) {
        return '54321';
    }

    return $layout_id;
}
add_filter( 'builder_filter_current_layout', 'custom_filter_positionvids_layout' );
1

You can use AND operator &&, you can retrieve the category by different parameters see codex for reference

function custom_filter_positionvids_layout( $layout_id ) {
    if ( is_post_type_archive( 'position_video' ) && is_category( array('category1_id', 'category2_id') ) ) {
        return '58bef4ba370de';
    }

    return $layout_id;
}
add_filter( 'builder_filter_current_layout', 'custom_filter_positionvids_layout' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.