Wednesday, 7 August 2013

Assign all custom fields to variables with the same name?

Assign all custom fields to variables with the same name?

If you have custom fields in a Wordpress post, is there a way to set all
the custom fields to variables of that same name automatically?
I.e instead of
$custom_fields = get_post_custom();
if (isset($custom_fields['field_1'][0])) { $field_1 =
$custom_fields['field_1'][0]; }
if (isset($custom_fields['field_2'][0])) { $field_2 =
$custom_fields['field_2'][0]; }
etc.....
Is there a way to skip those ifs and simply assign every valid custom
field to a var automatically?

No comments:

Post a Comment