admin管理员组

文章数量:1291089

How to print array values for custom field meta.

My code -

<?php $item = get_post_meta($post->ID, 'occupationalCategory', false); ?>
<?php print_r( $item[0]['occupationalCategory'] ); ?>;
<?php print_r( $item[1]['occupationalCategory'] ); ?>

Output - none

How to print array values for custom field meta.

My code -

<?php $item = get_post_meta($post->ID, 'occupationalCategory', false); ?>
<?php print_r( $item[0]['occupationalCategory'] ); ?>;
<?php print_r( $item[1]['occupationalCategory'] ); ?>

Output - none

Share Improve this question asked Jun 2, 2021 at 17:49 PuneetPuneet 477 bronze badges 2
  • if you set third parameter of get_post_meta to true, it will also return an array. Then try just echo $item['0] – anton Commented Jun 2, 2021 at 18:10
  • @anton It's working now. Check Image - how to print US, 29.622, TX because the array is not print with updated code. – Puneet Commented Jun 5, 2021 at 17:02
Add a comment  | 

1 Answer 1

Reset to default 1

Based on the screenshot I assumed is var_dump of your $item The code should look like

<?php $item = get_post_meta($post->ID, 'occupationalCategory', false); ?>
<?php print_r( $item['occupationalCategory'][0] ); ?>;
<?php print_r( $item['occupationalCategory'][1] ); ?>

$item contains array, with a element which key is 'occupationalCategory', this element points to other array with two elements

本文标签: customizationHow to print Array values of custom Fields Meta