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 know how to display field content if the field has content.

$monday = get_post_meta($post->ID, '_cmb_open_monday', true);
if ( ! empty ( $monday ) ) {
    echo 'content';
}

How do I display the content if one of the fields from the metabox "store_openingtimes" has content? Maby this explains better what i want to do:

$storeopen = Get all meta from metabox id "store_openingtimes"
if ( ! empty ( $storeopen ) ) {
    echo 'content';
}
share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

You have to list the keys of the meta fields saved in the metabox, because their is no function to dynamically retrieve all the fields saved in specific metabox. For example:

$store_openingtimes_keys = array(
  '_cmb_open_monday', '_cmb_open_tuesday', '_cmb_open_wednesday', '_cmb_open_thursday',
  '_cmb_open_friday', '_cmb_open_saturday', '_cmb_open_sunday'
);
// all the not empty meta for the post
$meta = array_filter( get_post_custom($post->ID) );
// there are any not empty meta that is one of the store opening times?
$times_meta = array_intersect( array_keys($meta), $store_openingtimes_keys );
if ( ! empty($times_meta) ) { // if so, show content
   echo $content;
}
share|improve this answer
    
Thanks @g-m This is exactly what I'm looking for! –  Lasse M. Tvedt Nov 16 '13 at 15:07
add comment

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.