Support

Account

Home Forums Front-end Issues How to display default values on front end?

Helping

How to display default values on front end?

  • I have a WP site with about 300 media files (PDFs), all with a custom image field attached.

    This custom image field has a default value set (which is what I want displayed).

    The problem is: default values are not displayed on the front end (until the post is re-published).

    I’m been stuck on trying to achieve either of the following:

    –Enable default ACF values to display on the front end OR
    –Bulk re-publish all media files
    (The end goal is to display the media files in a list/table format with text links to download them and the image icon for labeling purposes)

    Can anyone point me in the right direction?

  • If this default image value, or the field itself, did not exist when you first saved the posts then you can try getting the field value by the field key instead of the field name. The issue if a field did not exist when the post was initially saved is that ACF does not know how to find the field key in order to use the default value.

    If that does not work then you need to code it into your template

    
    $value = get_field('your-field-name');
    if (!$value) {
      $value = ?? set default value
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to display default values on front end?’ is closed to new replies.