Question

I'm trying to create a loop to read all the meta_value records from a given post_id. The idea is to gather all the meta_value's data from wp_postmeta table related to post_id number and print them as a list. But so far, I couldn't make this work. The issue is my 'custom_fields' variable. There I need to put my meta_key. But I have several meta_key per post_id. For example, the post_id 2171 has data2,date3,data4,data5.. data19 as meta_key. So, how can I get this working?

function jb_applicant() {
   global $wpdb;
   $custom_fields = get_post_custom(2171); //2171 is the post_id that I'm trying to gather the data from
   $my_custom_field = $custom_fields['data2'];
   $op = '';
   foreach ( $my_custom_field as $key => $value ) {
      $op .= $key . " => " . $value . "<br />";
   }
   return $op;
}
add_shortcode('applicant', 'jb_applicant');

Thanks

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top