0

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';
}
1

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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