Site logo

Archived topic

Content Template No Posts

5 replies · Started by Mike on May 11, 2022

Viewing posts 1–6 of 6

I have got a nice content template setup and working perfectly, until there is no posts...

It seems when no posts can be found instead of using the default no-results.php the content template will instead display a blank post with the default UNIX date of 1st Jan 1970.

Am I missing something here?

Mike

And then I worked out the answer!

add_filter( 'generate_element_display', function( $display, $element_id ) {

    global $post;

    if ( 199 === $element_id && is_post_type_archive('events') && !$post ) {

        $display = false;

    }

    return $display;

}, 10, 2 );

Hi there,

It is something we are aware of and we'll see if we can address that in a future update.

In the meantime - Thanks for sharing your solution!

I will adjust this for more general usage:

add_filter( 'generate_element_display', function( $display, $element_id ) {
    global $post;
    if ( !$post && get_post_meta( $element_id, '_generate_block_type', true ) == 'content-template' ) { 
        $display = false;
    }
    return( $display );
}, 10, 2 );

Thanks for sharing that !!

This archived topic is closed to new replies.