[wp-hackers] Ability to compare arrays in checked() function

Matt Martz matt at sivel.net
Thu Aug 6 12:18:01 UTC 2009

On Thu, Aug 6, 2009 at 8:10 AM, Sudar Muthu<sudar at sudarmuthu.com> wrote:
> Hi all,
> The checked() function (present in wp-admin/includes/template.php) checks
> whether two parameters passed to it are equal and then outputs
> checked='checked', which can be used in forms having checkboxes or radio
> buttons.
> Sometimes (particularly for checkboxes), we might need to check for multiple
> values. So I am proposing a change to the checked() function.
> It can first check whether the default value is an array and if yes, it can
> return checked='checked' if the current value is present in the default
> array.
> I have created a new ticket and have attached a patch with this change.<
> http://core.trac.wordpress.org/ticket/10556>
> Do let me know what you guys think about it.

I have always used:

<?php checked(true, in_array('needle', $options['haystack'])); ?>

Seems to work fine and is pretty easy.

Matt Martz
matt at sivel.net

More information about the wp-hackers mailing list