Title: [Plugin: More Fields] Checkbox issue
Last modified: August 19, 2016

---

# [Plugin: More Fields] Checkbox issue

 *  Resolved [ucarmetin](https://wordpress.org/support/users/ucarmetin/)
 * (@ucarmetin)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-more-fields-checkbox-issue/)
 * Hi there!
 * I’m running More Fields v 2.0.3 on my locally installed WP 3.0.1. I’ve created
   box using More Fields. The box is filled bunch of fields and a checkbox. I want
   the checkbox function like a control. For instance, if the user checks the checkbox,
   values inserted in the custom fields, which are in the box, will be attached 
   to post and displayed along with it. However, I cannot make it work so far.
 * Any idea or piece of helpful code that you can give me, so that I can resolved
   this problem?
 * Appreciate your help.
 * [http://wordpress.org/extend/plugins/more-fields/](http://wordpress.org/extend/plugins/more-fields/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Kal Ström](https://wordpress.org/support/users/kalstrom/)
 * (@kalstrom)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-more-fields-checkbox-issue/#post-1740999)
 * I guess what you want to do is to check if that value is there. If so then you
   run the other queries.
 *     ```
       <?php if ($checkbox_value = get_post_meta($post->ID, 'custom-field-key-name', true)) : ?>
   
       […]
   
       <?php endif; ?>
       ```
   
 *  Thread Starter [ucarmetin](https://wordpress.org/support/users/ucarmetin/)
 * (@ucarmetin)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-more-fields-checkbox-issue/#post-1741118)
 * Hej Kalstrom,
 * That’s the solution I was looking for. Thank you so much.
    Your help is much 
   appreciated.
 *  [alex chousmith](https://wordpress.org/support/users/chousmith/)
 * (@chousmith)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-more-fields-checkbox-issue/#post-1741166)
 * I also ran into a problem with Checkboxes, but mine was a problem with the back
   end, on a post Edit page…
 * I had a checkbox, and if i check it ON (value checkbox_on), and hit Update, the
   post meta gets saved with that field and value=”checkbox_on” aok. However, when
   I go back to edit that page again, the Checkbox itself was not showing up as 
   CHECKED.
 * I was able to tweak a couple of lines in the “function field_type_render” of 
   the more-fields-settings-object.php file, and fixed this issue. The things I 
   changed were :
 * Line 363, changed from
 * `$value = (strstr($value_raw, '*') && ($html_selected)) ? substr($value_raw, 
   1) : $value_raw;`
 * to
 * `$value = (strpos($value_raw, '*')!==false && strlen($value_raw)>1 && ($html_selected))?
   substr($value_raw, 1) : $value_raw;`
 * Line 381-382, changed from
 *     ```
       else $html = str_replace('%selected%', '', $html);
       if ($value_stored == 'checkbox_on') $html = str_replace('%selected%', $html_selected, $html);
       ```
   
 * to
 *     ```
       else if ($value_stored == 'checkbox_on') $html = str_replace('%selected%', $html_selected, $html);
       else $html = str_replace('%selected%', '', $html);
       ```
   
 * i am not 100% sure if this is the correct solution to the problem, but at least
   with this change, Checkboxes maintain their checked/unchecked value
 *  [alex chousmith](https://wordpress.org/support/users/chousmith/)
 * (@chousmith)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-more-fields-checkbox-issue/#post-1741167)
 * i am not sure if this too has anything to do with it, but i also noticed that
   in the more-fields-field-types.php file, Line 81 , which is under the “CHECKBOX”
   area, has
 * `$f['radio']['html_after'] = "%caption%";`
 * f[‘radio’] rather than f[‘checkbox’] ?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘[Plugin: More Fields] Checkbox issue’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/more-fields.svg)
 * [More Fields](https://wordpress.org/plugins/more-fields/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/more-fields/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/more-fields/)
 * [Active Topics](https://wordpress.org/support/plugin/more-fields/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/more-fields/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/more-fields/reviews/)

## Tags

 * [control](https://wordpress.org/support/topic-tag/control/)
 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [display](https://wordpress.org/support/topic-tag/display/)

 * 4 replies
 * 3 participants
 * Last reply from: [alex chousmith](https://wordpress.org/support/users/chousmith/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-more-fields-checkbox-issue/#post-1741167)
 * Status: resolved