[Resolved] Display custom template for CPT only if there is data to loop on

Home Forums Support [Resolved] Display custom template for CPT only if there is data to loop on

Home Forums Support Display custom template for CPT only if there is data to loop on

  • This topic has 3 replies, 2 voices, and was last updated 2 years ago by David.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2142385
    Thibaud

    Hi guys !

    I have build a custom template inside the GeneratePress Builder for one of my CPT.
    I use “Dynamic Content” and “Dynamic Image” blocks, but when I have no data (CPT) to loop on, the box is show one time with empty data inside it.

    Is there a possibility to display this custom template only if I have data to loop on ? (like en for-else loop to speak dev)

    Thank you for your help !
    Thibaud

    #2142552
    David
    Staff
    Customer Support

    Hi there,

    we had one other reported issue of this, see Tom’s temporary solution for that here:

    https://generatepress.com/forums/topic/posts-page-as-company-job-postings/page/2/#post-2118759

    To use that try the following snippet:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
    
        if ( 675 === $element_id && ! have_posts() ) {
            $display = false;
        }
    
        return $display;
    }, 10, 2 );

    Where the 675 is you need to replace that with the ID of the element.

    #2144182
    Thibaud

    Hi David,

    Sorry I couldn’t find this issue in my researches.
    Perfect, it works thanks !

    #2144447
    David
    Staff
    Customer Support

    Its only come up once 🙂 And it took me a while to find it ( well i asked Tom who found it lol ).

    Glad to be of help. Its something we will fix in the future.

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