Hi on my site I'm importing the data, and couple of text field and multi-line field are set for default value and I'm trying to view them on front-end but I can't see them unless I go on every page of post type and update the page.
Since I'm importing data for post type I can't go on each and every page and update them individually.
So I'm looking for a solution that I can't show my default value for the text-field without going to each and every page and update them in .php
Thanks looking forward for your answer.
Dear laura,
I suggest you try with Views shortcode [wpv-conditional] to check if the custom field is empty, display the default value, if the custom field isn't empty, display the field value, for example, there is a custom single line field "test-field":
[wpv-conditional if="( empty($(wpcf-test-field)) )"]
This field is empty or does not exist, display the default value
[/wpv-conditional]
[wpv-conditional if="( empty($(wpcf-test-field)) )" evaluate="false"]
here display the field value:
[types field="test-field"][/types]
[/wpv-conditional]
More help:
https://toolset.com/documentation/views-shortcodes/#wpv-conditional
what would I write instead of
This field is empty or does not exist, display the default value
is there a PHP code to display default value if the field is empty.
Thanks
You can try with wordpress function get_post_meta():
https://developer.wordpress.org/reference/functions/get_post_meta/
Check if the field value is empty, then display the default value.
I meant to as with what would I be calling default text in field like there should be some kind of term for that ...
I'm attaching a screenshot for reference
I assume we are talking about in wordpress admin side, when user edits a post, you are going to display a default value in the input box.
If your custom fields are created with Types plugin, please edit them, there are two options you can try:
1) Placeholder: This value is being displayed when the field is empty in the post editor.
2) Default Value: This is the initial value of the field.
See screenshot 1.jpg