WordPress: How to retrieve custom field from normal posts

Sponsors

Many people use the custom meta fields in wordpress posts. In this article I will show you how to retrieve the custom field from wordpress post. For fetching the custom fields you just need to use the following code.

$key_values = get_post_meta($post->ID, 'key');

If you are using normal post or custom post type above function will work. Here is another code for fetching the custom post type meta values.
custom meta tags

$loop = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => 10 ) );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
the_content();
global $post;
$custom = get_post_custom($post->ID);
echo $thumbnail_url = $custom["thumbnail_url"][0];
echo $product_info = $custom["product_info"][0];
echo '
<div>';
the_content();
echo '</div>
';
endwhile;

Incoming search terms:

You may like following Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>