0

Before asking let me tell two things...
1)I know this is very east to someone, but it is hard to me.
2)I am facing this problem to create a WordPress template.That's why I have posted here.
Problem: When I print_r the following codes then

<?php 

          $home_starting_player_names = rwmb_meta( 'pb_home_starting_player_options', array( 'multiple' => true ) ); ?>

          <?php 
           foreach ( $home_starting_player_names as $home_starting_player ){?>
            <li role="presentation">
            <aside class="starting-player-image"><?php  echo get_the_post_thumbnail($home_starting_player); ?></aside>
            <aside class="starting-player-name"><?php  echo get_the_title($home_starting_player); ?></aside>
           <aside class="starting-player-number"><?php $var_dumps = get_post_meta($home_starting_player); 

           print_r ($var_dumps);

           ?></aside>
       <?php } 
        ?>

it outputs as follows (I have written only one here):

Array ( 
[_edit_last] => Array ( [0] => 1 )
 [_edit_lock] => Array ( [0] => 1477596212:1 )
 [pb_squad_number] => Array ( [0] => 10 ) 
[pb_player_date_birth] => Array ( [0] => 2016-09-02 )
)

Now I want to show the value of this key [pb_squad_number].I mean 10. Please help me through codes.

1

You can specify the key you want in get_post_meta:

echo get_post_meta( $home_starting_player, 'pb_squad_number', true );

WordPress loads all meta for any single meta call, so calling get_post_meta multiple times doesn't introduce any extra overhead.

| improve this answer | |
1

Do you mean this? : var_dump($var_dumps[pb_squad_number][0]);

| improve this answer | |
  • You are also right but 2@Milo's answer works more efficiently for me.Thanks – bdtheme Oct 28 '16 at 18:59

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.