WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] checked ( $blah, $blah2 ) and arrays

[Resolved] checked ( $blah, $blah2 ) and arrays

  • I want to echo checked = “checked”
    Since I’m writing a theme for submission to WP repository I need to use checked ( $blah, $blah2 )
    However, the theme uses an array of checkboxes
    I have been using

    if (in_array ($miscellaneous_checkbox_key, $miscellaneous_checkbox_checked))
    			{
    			echo ' checked="checked"';
                            }

    How do I do this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Bumped.
    From http://codex.wordpress.org/Theme_Review

    < For checkboxes and select options, Themes are required to use the checked() and selected() functions for outputting checked=”checked” and selected=”selected”, respectively. >

    I’m probably being daft, but how can I use that code – which echoes output, so I can’t even do anything with it in php – when I have an array of checkboxes (as an example) and I have to go through that array to see if my conditions are being met? It looks to my simple mind as if that function only matches one specific condition to one specific condition.

    OK, checked the function, it only matches strings, so I’ve replaced my neat if ( array_key_exists () ) and if (in_array () ) with foreach loops.

    Stupid checked() function, can’t see the point of it but if we have to have it perhaps it could check for the presence of a string in an array for multiple checkboxes.

    Hi, I use:

    function bnm_checked($haystack, $current) {
    	if(is_array($haystack) && in_array($current, $haystack)) {
    		$current = $haystack = 1;
    	}
    	checked($haystack, $current);
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] checked ( $blah, $blah2 ) and arrays’ is closed to new replies.