wordpress get posts with custom field value

wordpress tutorial, wordpress get posts with custom field value. Many people use the custom meta fields in wordpress posts. Here given code snippet for same.  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.

wordpress get posts with custom field value

$key_values = get_post_meta($post->ID, 'key');
custom meta tags
wordpress get posts with custom field value

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.

$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;

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.