how to call custom fields in loop in wordpress

by 6 replies
7
i tried to add player to the post through custom fields in wordpress
i added "player" key to the custom fields.
now i want this player to display in somewhere in theme loop.
i used the code :
<?php $player = get_post_meta($post->ID,'player', true); ?>
but player doesn't display at all . is this code correct .
please help.:confused:
#programming #call #custom #fields #loop #wordpress
  • I do not think that you have done this correctly.
    Rather you should had look at some other option before doing this.
  • What is 'player'? Is it a string value? Have you set it before trying to access it?
  • I don't know if it will help you but you should try the below code :

    $player = get_post_meta($post->ID,'player', true);

    Don't start php code inside another php code.

    Hope it helps!
  • It'll depend on what $player is, but in the first instance you'd need to output it:

    <?php
    $player = get_post_meta(get_the_ID(), 'player', true);
    echo $player;
    ?>
  • you can use get_post_meta (Function Reference/get post meta « WordPress Codex) to retrieve specific custom meta/field.

    or

    you can use get_post_custom (Function Reference/get post custom « WordPress Codex) to retrieve all custom meta/field in a post/page and assign it to a variable
    • [1] reply
    • Yes, you're right n7 Studios. The instruction "echo $player;" was
      missing. We also can write this:

      PHP Code:
      <?php echo do_shortcode(get_post_meta(get_the_ID(), 'player'true)); ?>
  • Banned
    [DELETED]

Next Topics on Trending Feed