phprockers-logo

How to get the custom field values in wordpress?

First we should know, what are the custom fileds values are available now. get_post_custom_keys() can be used to find all the custom fields in current post.

<?php
$get_list_custom_fileds = get_post_custom_keys();
print_r($get_list_custom_fileds);
?>

Then we have to esily get the particular custom field value for current post. Here the example of get the book author name for current post.

<?php
$book_author = get_post_custom_values('_book_author');
echo "<div class='book-author'".$book_author[0].'</div>';
?>

0 comments:

Post a Comment