Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

How do you set a default image for a Post Template in a Query Loop

  • We have successfully created an Element that has a Query Loop with Post Template for our archives pages. All looks fine, but many of the old posts don’t have a Featured Image.

    We understand that we could use “Remove block if link is empty” to alleviate the issue, but that defeats the purpose of creating a neat layout that looks attractive.

    Currently, the posts without a Featured Image pick up an image from one of the posts, but we can’t see why or how.

    We want to set a default image manually for all posts that don’t currently have an image.

    BTW this is a WordPress site that has been around for over a decade, so manual intervention is not a possibility.

    We will eventually grant every post a Featured Image, but we just need a fix for now.

  • Hi there,

    hmmm… I think there must be some other plugin or function in play here.
    The GB Image Block, when set to Display Dynamic Data e.g featured image, will only print the block out IF there is dynamic data.

    Any possibility theres some other code in play ?

  • WP Posts was activated temporarily prior to us using Query Loop. But when that was active it did not grab the featured image that we see now.

    The site is in dev mode with no extra plugins active.

    But at the same time, the site is +20 years old and been using WordPress for over a decade so there could be some deprecated databases. But I doubt that is the issue here.

    But this post is from 2020 so I have no idea why it has chosen this one.

    Regardless, the question still is “How do you nominate a default image?”

    If the answer is you can’t – change it. You should be able to. I have made the that request from developers for years. If I wanted a backend that required all fields be filled I would be using Wix or a template resolve from Envato.

    We have built custom WordPress sites for over a decade and have convinced our clients that the way forward is GP & GB. Please don’t make me wrong.

    Happy to give you access if that helps. This site should have been live YESTERDAY.

  • The GB Image block has the generateblocks_dynamic_image_fallback filter hook.
    So you an do this:

    add_filter( 'generateblocks_dynamic_image_fallback', function( $url ) {
        if ( ! $url ) {
    	return 'https://picsum.photos/480';
        }
        return $url;
    }, 10, 1 );

    You can try that, but somehow GB is picking up an image from somewhere so it may not meet the ! $url condition. Let me know

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