开发者

Trying to show a button only when a Wordpress custom field value is present

开发者 https://www.devze.com 2023-03-10 17:00 出处:网络
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 contain

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
}
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消