get custom fields value in wordpress theme


/ Published in: PHP
Save to your folder(s)

get custom fields value in wordpress theme


Copy this code and paste it in your HTML
  1. To be used only inside WordPress’s Loop
  2.  
  3. <?php echo get_post_meta($post->ID, 'custom_field_name', true); ?>
  4.  
  5. It displays the value of the custom field. Replace “custom_field_name” with the chosen name of your custom field.
  6.  
  7. To display the value outside the loop use
  8.  
  9. <?php
  10. global $wp_query;
  11. $postid = $wp_query->post->ID;
  12. echo get_post_meta($postid, 'custom_field_name', true);
  13. ?>

URL: http://codesnippets.info/wordpress/get-custom-fields-value/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.