Question

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?

Was it helpful?

Solution

i 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'.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top