Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1406460

    We’re using the blog post element in the layout builder. It shows the blog posts, but also posts from a custom post type. How to filter these out?

    #1406499

    Hey bonsaimedia,

    Thank you for the inquiry.

    What is the name of the custom post type (cpt)? You should be able to exclude items from the cpt by adding this code in the functions.php file.

    function avia_post_slide_query_mod($query, $params) {	
        foreach($query['post_type'] as $key => $value) {
            if( $value == 'custom-post-type-name' ) {
                unset($query['post_type'][$key]);
            }      
        }
    
        return $query;
    }
    add_filter('avia_post_slide_query', 'avia_post_slide_query_mod', 10, 2);
    

    Just replace the placeholder (custom-post-type-name) with the actual name or slug of the custom post type.

    Best regards,
    Ismael

    #1423762

    i think ismaels code should work.
    on looking for this from docu:

    click on your CPT on dashboard and look to the url window on top – what post-type you see there

    f.e. on portfolio ( which is a CPT too ). you see: edit.php?post_type=portfolio

    try a shortform – then with the info you get from that url window

    add_filter("avia_post_slide_query", function($query) {
        unset($query["post_type"]["vacature"]);
        return $query;
    }, 10, 1);
    #1423775

    Hi,

    I checked and that’s right. See link below for the CMS URL But crazy enough I keep seeing that CPT tile in the blog overview.
    This is how the functions code looks like now:

    function avia_post_slide_query_mod($query, $params) {
    foreach($query[‘post_type’] as $key => $value) {
    if( $value == ‘vacature’ ) {
    unset($query[‘post_type’][$key]);
    }
    }

    return $query;
    }
    add_filter(‘avia_post_slide_query’, ‘avia_post_slide_query_mod’, 10, 2);

    #1423857
Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘CPT in blog posts element’ is closed to new replies.