Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using the Advanced Custom Fields plugin and want to read the value of the custom fields. For dropdown and text fields, this is straightforward as the value is kept in plain text, so the get_post_custom_values functions works.

For multi-select field, however, ACF keeps data like this:

a:1:{i:0;s:3:"Value2";}

So the sensible thing to do is to use the get_value function from ACF to read the value and parse it into objects.

In the ACF plugin, the first line does:

$acf = new Acf();

So I assumed I could just use the $acf variable in my plugin and do:

$afc->get_value ($post_id, $key);

but received error with

PHP Notice:  Undefined variable

I am new to php development so I might not have understood the scoping rule correctly. So, what's the right way to do this and what am I doing wrong?

share|improve this question

1 Answer 1

The multi-select field you referenced appears to be stored in PHP serialized format, which is used for "storing or passing PHP values around without losing their type and structure".

To unserialize a custom field value you need to use the unserialize() function:

$multi_select_field = unserialize( get_post_meta( get_the_ID(), 'custom_field_key', true ) );
share|improve this answer
    
Thanks for your answer, I will try out this approach. However, I would still like to know how I can call a function from another plugin. –  ltfishie Mar 14 '12 at 21:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.