Title: Setting Default Values for Empty Fields Programmaticaly?
Last modified: August 21, 2016

---

# Setting Default Values for Empty Fields Programmaticaly?

 *  Resolved [inactive](https://wordpress.org/support/users/nurdanucergmailcom/)
 * (@nurdanucergmailcom)
 * [13 years ago](https://wordpress.org/support/topic/setting-default-values-for-empty-fields-programmaticaly/)
 * Hello and thanks for a great plugin.
 * Is there any way to set default values programmatically perhaps via a hook?
 * I would like to check for empty fields (for example a cover photo field) and 
   set a default value for it.
 * Similar to this, but with bp_get_profile_field_data():
 * `$CoverImage = ($CoverImage = get_post_meta($post->ID, 'tb_width', true)) ? $
   CoverImage : 120;`
 * Many thanks.
 * [http://wordpress.org/extend/plugins/buddypress-xprofile-custom-fields-type/](http://wordpress.org/extend/plugins/buddypress-xprofile-custom-fields-type/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [donmik](https://wordpress.org/support/users/atallos/)
 * (@atallos)
 * [13 years ago](https://wordpress.org/support/topic/setting-default-values-for-empty-fields-programmaticaly/#post-3683012)
 * In the latest version 1.5.4, I have created a filter “bxcft_show_field_value”.
   You can use it to check if the field is empty.
 *  Thread Starter [inactive](https://wordpress.org/support/users/nurdanucergmailcom/)
 * (@nurdanucergmailcom)
 * [13 years ago](https://wordpress.org/support/topic/setting-default-values-for-empty-fields-programmaticaly/#post-3683095)
 * Thank you, could you possibly post a small snippet as to how I can use it in 
   templates?
 * `<?php function bxcft_get_field_value('myfield'); ?>`
 * doesn’t seem to work.
 *  Thread Starter [inactive](https://wordpress.org/support/users/nurdanucergmailcom/)
 * (@nurdanucergmailcom)
 * [13 years ago](https://wordpress.org/support/topic/setting-default-values-for-empty-fields-programmaticaly/#post-3683096)
 * * Sorry I meant:
 * `<?php function bxcft_show_field_value('field=myfield'); ?>`
 *  Plugin Author [donmik](https://wordpress.org/support/users/atallos/)
 * (@atallos)
 * [13 years ago](https://wordpress.org/support/topic/setting-default-values-for-empty-fields-programmaticaly/#post-3683101)
 * In the FAQ which I’ve uploaded today, you can see how to use the filter. In your
   case I suppose you need to do something like this:
 *     ```
       add_filter( 'bxcft_show_field_value', 'my_show_field', 15, 4);
       function my_show_field($value_to_return, $type, $id, $value) {
           if ($type == 'image') {
               $value = str_replace("<p>", "", $value);
               $value = str_replace("</p>", "", $value);
               if ($value != '') {
                      return '<p><img src="'.$uploads['baseurl'].$value.'" alt="" /></p>';
               } else {
                    return YOUR_DEFAULT_IMAGE;
               }
           }
           return $value_to_return;
       }
       ```
   
 * Something like this might work.
 *  Thread Starter [inactive](https://wordpress.org/support/users/nurdanucergmailcom/)
 * (@nurdanucergmailcom)
 * [13 years ago](https://wordpress.org/support/topic/setting-default-values-for-empty-fields-programmaticaly/#post-3683102)
 * Thank you, that’s exactly what I need.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Setting Default Values for Empty Fields Programmaticaly?’ is closed to
new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/buddypress-xprofile-custom-fields-
   type.svg)
 * [Buddypress Xprofile Custom Fields Type](https://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/buddypress-xprofile-custom-fields-type/)
 * [Active Topics](https://wordpress.org/support/plugin/buddypress-xprofile-custom-fields-type/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/buddypress-xprofile-custom-fields-type/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/buddypress-xprofile-custom-fields-type/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [inactive](https://wordpress.org/support/users/nurdanucergmailcom/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/setting-default-values-for-empty-fields-programmaticaly/#post-3683102)
 * Status: resolved