Archived topic
Content Template No Posts
5 replies · Started by Mike on May 11, 2022
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
Also to follow up, I did see this link - https://generatepress.com/forums/topic/no-posts-template-on-custom-post-type-archive/
However, I am not keen on that solution as it means I have to maintain another GP element rather than the built in no-results.php
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 !!