Trying to show a button only when a Wordpress custom field value is present
On a Wordpress site, in a product template, I have a section that shows a custom field value. On the site, the container is hidden by default. A visitor can click a button that slides open the container. The button is just in the template, static.
I am using this to show the value of my custom field:
if ( func开发者_C百科tion_exists('get_custom_field_value') ){
get_custom_field_value('fieldname', true);
}
So what I'm trying to do is make it so the button only shows up if there is actually a value in the custom field.
I'm a total PHP newb. Any advice?
You can use get_post_meta() to check if custom field is empty or not:
<?php
if( get_post_meta($post_id, 'fieldname', true) != '')
{
//print your button here
}
?>
精彩评论