Funny you mention this, I did a similar thing not with posts but with pages and a custom theme menu. I think this might work:
<?php
$single_posts = echo get_post_meta($post->ID, 'Products', true);
$post_array = array($single_posts); //construct array for single posts id's
$args = array('order' => 'desc', 'p' => $post_array);
$single_post_fields = new WP_Query($args);
$count = 0; ?>
<div role="complementary" class="homepage-widgets" id="footer-widget-area">
<?php while ($single_post_fields->have_posts()) : $single_post_fields->the_post();
$count++;
$do_not_duplicate = $post->ID; ?>
<p>Whatever your HTML and WP stuff is to call the post (the_title, the_content, etc)</p>
<?php endwhile; wp_reset_query(); ?>
I haven’t tried it, but its similar to my page code so it should work.
Hey, Thanks for your code.
I tried it out but I can’t get it to work entirely.
FYI : I have a comma separated list of ids in my “Product” field (i.e. “1, 56, 98, 203”).
- If I test the $single_posts variable it lists the post ids as it should.
- If I test the $post_array variable it outputs “array” instead of the values of the array.
Here are my findings so far. Do you have any ideas?
Here’s the non working version
<?php $products = get_post_meta($post->ID, 'products', true);
if($products != '') {
$single_posts = get_post_meta($post->ID, 'products', true);
$post_array = array($single_posts); //construct array for single posts id's
$args = array(
'order' => 'desc',
'p' => $post_array
);
$single_post_fields = new WP_Query($args);
$count = 0; ?>
<div class="categoryimages">
<?php echo $args ?>
<ul>
<?php while ($single_post_fields->have_posts()) : $single_post_fields->the_post(); $do_not_duplicate = $post->ID; ?>
<li><?php the_post_thumbnail('thumbnail'); ?></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
</div>
<?php } ?>
This version displays the first post in the list of ids (better, but I need it to display all of them)
<?php $products = get_post_meta($post->ID, 'products', true);
if($products != '') {
$single_posts = get_post_meta($post->ID, 'products', true);
$post_array = array($single_posts); //construct array for single posts id's
$args = array(
'order' => 'desc',
'p' => $single_posts
);
$single_post_fields = new WP_Query($args);
$count = 0; ?>
<div class="categoryimages">
<?php echo $args ?>
<ul>
<?php while ($single_post_fields->have_posts()) : $single_post_fields->the_post(); $do_not_duplicate = $post->ID; ?>
<li><?php the_post_thumbnail('thumbnail'); ?></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
</div>
<?php } ?>