admin管理员组文章数量:1317572
I'm attempting to add a class to posts when the meta key 'checkbox' is clicked. Here's what I have:
<?PHP $checkbox = get_post_meta($post->ID, 'checkbox', true);
if (!empty($checkbox)){ $has_video = 'icon-has_video'; }
else {$has_video = '';}
?>
<a class='<?php echo $has_video; ?>' href='<?php the_permalink(); ?>'>
... but so far it's not working. Any suggestions?
I'm attempting to add a class to posts when the meta key 'checkbox' is clicked. Here's what I have:
<?PHP $checkbox = get_post_meta($post->ID, 'checkbox', true);
if (!empty($checkbox)){ $has_video = 'icon-has_video'; }
else {$has_video = '';}
?>
<a class='<?php echo $has_video; ?>' href='<?php the_permalink(); ?>'>
... but so far it's not working. Any suggestions?
Share Improve this question edited Nov 1, 2020 at 20:46 Camille Roney asked Nov 1, 2020 at 20:15 Camille RoneyCamille Roney 153 bronze badges1 Answer
Reset to default 0i suggest you check the the value of $checkbox by either checking checkbox under meta_key column in wp_postmeta or *your prefix_postmeta table in your database or simply do var_dump($checkbox); for testing if its 0 or null or an empty string or so then your if condition will not return true and $has_video will not be assigned to 'icon-has_video'.
本文标签: custom fieldSet class if a meta value is set within post archive
版权声明:本文标题:custom field - Set class if a meta value is set within post archive 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742021866a2414823.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论