0

How to print array values for custom field meta.

enter image description here

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

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

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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