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');
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;