WordPress.org

Ready to get started?Download WordPress

Forums

More Fields
[resolved] Checkbox issue (5 posts)

  1. ucarmetin
    Member
    Posted 3 years ago #

    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/

  2. kalstrom
    Member
    Plugin Author

    Posted 3 years ago #

    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; ?>
  3. ucarmetin
    Member
    Posted 3 years ago #

    Hej Kalstrom,

    That's the solution I was looking for. Thank you so much.
    Your help is much appreciated.

  4. alex chousmith
    Member
    Posted 3 years ago #

    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

  5. alex chousmith
    Member
    Posted 3 years ago #

    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'] ?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic