How to Hide/Show Div Based on Meta Checkbox
-
I’m trying to hide a div based on whether a custom metabox check box has been checked. I’ve been struggling with this for a while. Is this possible?
Here is the function that sets it up in my functions.php
// Checkbox Meta add_action("admin_init", "checkbox_init"); function checkbox_init(){ add_meta_box("checkbox", "Check to Show Bubbles", "checkbox", "homefeature", "normal", "high"); } function checkbox(){ global $post; $custom = get_post_custom($post->ID); $field_id = $custom["field_id"][0]; echo '<label>Show Bubbles?</label>'; $field_id_value = get_post_meta($post->ID, 'field_id', true); if($field_id_value == "yes") { $field_id_checked = 'checked="checked"'; } echo ' <input type="checkbox" name="field_id" value="yes" '.$field_id_checked.' />'; } // Save Meta Details add_action('save_post', 'save_details'); function save_details(){ global $post; if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post->ID; } update_post_meta($post->ID, "field_id", $_POST["field_id"]); } function custom_content($id) { $field_id = get_post_meta($id, 'field_id', true); if($field_id == yes) { echo '<script type="text/javascript">'; echo '$(this).mouseover(function() {'; echo "$('#mainFeatureFlashBG').css({'display' : 'block'})"; echo '};</script>'; } else{ echo '<script type="text/javascript">'; echo '$(this).mouseover(function() {'; echo "$('#mainFeatureFlashBG').css({'display' : 'none'})"; echo '};</script>'; } }
Here is my PHP Loop Where I’m trying to Call it
<ul> <?php $args=array( 'beerlogo'=>'miller', 'post_type' => 'homefeature', 'post_status' => 'publish', 'posts_per_page' => -1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <li class="image-rollover"><a href="<?php echo esc_url(get_post_meta($post->ID, 'homefeature_custom_link', true)); ?>"><?php the_post_thumbnail('full'); ?> <?php //Is the Checkbox for Bubbles Checked? custom_content(get_the_ID()); ?> </a> </li> <?php endwhile; } wp_reset_query(); ?> </ul>
- The topic ‘How to Hide/Show Div Based on Meta Checkbox’ is closed to new replies.