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.

This might might be more of a PHP question - but does deal with a WordPress plugin, Advanced Custom Fields

I am using a global select option to store a specific Location (custom post type) as the headquarters. I am storing the value as such:

function options_headquarters() {
    foreach(get_field('option_headquarters','options') as $post_object) {
        $options_headquarters = $post_object->ID;
        return $options_headquarters;
    }
}

What I am fuzzy on is - since my option is only allowed to grab one value -- is there an alternative to using a foreach statement (to grab just a specific array value) and still applying it to the post_object?

That function stores the postID of that Location. I am currently outputting this in my template as:

echo get_field('location_phone',options_headquarters());

which grabs a field called location_phone (a meta value within the Location custom post type) and specify a specific postID to grab the value from (the headquarters). Is there a better way of handling passing in this headquarters value? Just pulling this out of you know where, but something like options_headquarters('location_phone'); would be pretty sweet ;)

Thanks!

share|improve this question
    
function options_headquarters() { $headquarters_field = get_field('option_headquarters','options'); $headquarters = isset($headquarters_field[0]) ? $headquarters_field[0]->ID : NULL; return $headquarters; } Did it for me :) –  Zach Dec 19 '11 at 19:42
    
Zach, please add the solution as an Answer and mark it solved, so it gets out of the Unanswered category... –  brasofilo Jul 18 '12 at 20:35
    
Thanks for the heads up on this –  Zach Jul 18 '12 at 20:46
    
Cool! One last thing: in the Q, when you say "[...]using a global select option to store a specific CPT [...], do you mean "...using a Post Object Field Type..."? . . . Snapshot. –  brasofilo Jul 18 '12 at 21:12

1 Answer 1

up vote 1 down vote accepted

This ended up working for me:

function options_headquarters() { 
    $headquarters_field = get_field('option_headquarters','options'); 
    $headquarters = isset($headquarters_field[0]) ? $headquarters_field[0]->ID : NULL; 
    return $headquarters; 
}
share|improve this answer

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.