Site logo

[Resolved] Content Template No Posts

Home Forums Support [Resolved] Content Template No Posts

Home Forums Support Content Template No Posts

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2216045
    Mike

    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

    #2216048
    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

    #2216055
    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 );
    #2216072
    David
    Staff
    Customer Support

    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!

    #2468634
    Ido

    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 );
    #2469294
    David
    Staff
    Customer Support

    Thanks for sharing that !!

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