Site logo

Archived topic

"Nothing Found" message missing on blog when using content template element

3 replies · Started by Alessandro on August 5, 2022

Viewing posts 1–4 of 4

Hi, I'm using a modified version of the "Clinic" theme. It uses content template elements in the Blog page/archive. This works fine when there are blog posts present, but when there are no posts the page content is blank rather than showing the standard WordPress "Nothing Found" message.

Is there a way to bring that message back while still using the content templates? I tried to find a way to add a custom conditional message if no posts are found, but can't get anything to work. Thanks in advance!

Hi there,

for for now, the best method is to create another Block Element to contain your custom No Post Founds message. You can use a Page Hero or any Hook element. Set the Display Rules to match those of your Content Template.

Make a note of its post ID ( in the Browser URL when editing the post ) and the ID of the content template.

Then use the following PHP snippet to hide your custom no post element when we have posts, and hide the content template when we don't have post:

add_filter( 'generate_element_display', function( $display, $element_id ) {
    if ( 123 === $element_id && have_posts() ) {
        $display = false;
    }
	
    if ( 456 === $element_id && ! have_posts() ) {
        $display = false;
    }

    return $display;
}, 10, 2 );

123 change this to the ID of your custom no post element.
456 change this to the ID of your Content Template.

Thanks David, that works!

Glad to hear that!

This archived topic is closed to new replies.