In WordPress get post metadata when using wpalchemy class

Getting a post metadata values, when using the helpful wpalchemy class, differs a bit from the normal method.

You may get acquainted to the class here.

Get values on a single page

It’s as simple as…:


echo $custom_metabox->get_the_value('custom_field_name');

If you have trouble echoing out the value, try calling the global variable before it.


global $custom_metabox;
echo $custom_metabox_info->get_the_value('custom_field_name');

Get values on an archive page

This is a bit different from how you get the values on a single page. Example use case, get buy links to the reviewed album.


global $custom_metabox;//This is possible needed

$custom_metabox->the_meta();//This is needed on an archive page
echo $custom_metabox_->get_the_value('custom_field_name');//Get it

Example use case

Record review thingy. This is on a single page. We get values, put then in variables and finally spew ’em out as nice list:


    get_the_value('info_buy'); $info_buy_digi = $custom_metabox_info->get_the_value('info_buy_digi'); $info_artist = $custom_metabox_info->get_the_value('info_artist'); $info_release = $custom_metabox_info->get_the_value('info_release'); $info_label = $custom_metabox_info->get_the_value('info_label'); $info_year = $custom_metabox_info->get_the_value('info_year'); $info_catalogue = $custom_metabox_info->get_the_value('info_catalogue'); $info_format = $custom_metabox_info->get_the_value('info_format'); echo '
  • ' . $info_artist . '—' . $info_release . ' ' . $info_format . '
  • '; echo '
  • Released on ' . $info_label . ' with cat# ' . $info_catalogue . ' in ' . $info_year . '
  • '; if (!empty($info_buy)) {echo 'Get the 12" →';} if (!empty($info_buy_digi)) {echo 'Digital →';} echo ''; ?>

Loop a set of fields

You know those where you can add more fields by clicking a plus sign.


//Start the loop
while($custom_metabox->have_fields('music_uploader')) {
  $my_music_file  = $custom_metabox->get_the_value('music_file');
  $my_music_title = $custom_metabox_food_music->get_the_value('music_file_title');
  if(empty($my_music_file)) {
    //Do something if empty
  } else {
    //Do something else if not empty
  }
}//End the loop

Club-Mate, the beverage → club-mate.fi