Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use an individual checkbox value from a wordpress meta box?
    primarykey
    data
    text
    <p>I'm trying to use a metabox checkbox to hide/display on hover. The problem is it shows the div if any of the posts have the check box checked. I need it to toggle the div "on" &amp; "off" depending on if the checkbox is checked. Any help would be greatly appreciated. Here is the code in my functions.php: `// Checkbox Meta add_action("admin_init", "checkbox_init");</p> <pre><code>function checkbox_init(){ add_meta_box("checkbox", "Check to Show Bubbles", "checkbox", "homefeature", "normal", "high"); } function checkbox(){ global $post; $custom = get_post_custom($post-&gt;ID); $field_id = $custom["field_id"][0]; echo '&lt;label&gt;Show Bubbles?&lt;/label&gt;'; $field_id_value = get_post_meta($post-&gt;ID, 'field_id', true); if($field_id_value == "yes") { $field_id_checked = 'checked="checked"'; } echo ' &lt;input type="checkbox" name="field_id" value="yes" '.$field_id_checked.' /&gt;'; } // Save Meta Details add_action('save_post', 'save_details'); function save_details(){ global $post; if (defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE) { return $post-&gt;ID; } update_post_meta($post-&gt;ID, "field_id", $_POST["field_id"]); } function custom_content($id) { $field_id = get_post_meta($id, 'field_id', true); if($field_id == yes) { echo '&lt;script type="text/javascript"&gt;'; echo '$("this").mouseover(function() {'; echo "$('#mainFeatureFlashBG').css({'display' : 'block'})"; echo '}&lt;/script&gt;'; } else{ echo '&lt;script type="text/javascript"&gt;'; echo '$("this").mouseover(function() {'; echo "$('#mainFeatureFlashBG').css({'display' : 'none'})"; echo '}&lt;/script&gt;'; } }` </code></pre> <p>Here is my php: </p> <pre><code> &lt;ul&gt; &lt;!-- Begin Miller Beer Logo Query--&gt; &lt;?php $args=array( 'beerlogo'=&gt;'miller', 'post_type' =&gt; 'homefeature', 'post_status' =&gt; 'publish', 'posts_per_page' =&gt; -1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query-&gt;have_posts() ) { while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt; &lt;li class="image-rollover"&gt;&lt;a href="&lt;?php echo esc_url(get_post_meta($post-&gt;ID, 'homefeature_custom_link', true)); ?&gt;"&gt;&lt;?php the_post_thumbnail('full'); ?&gt; &lt;?php //Is the Checkbox for Bubbles Checked? custom_content(get_the_ID()); ?&gt; &lt;/a&gt; &lt;/li&gt; &lt;?php endwhile; } wp_reset_query(); ?&gt; &lt;/ul&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload