Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need some help with displaying some specific WordPress posts.

User's on my site can click on an 'Add to favorite' link which will then store that post ID in the user_meta table for that user as an array.

So when I put the following in my author.php template page...

<?php 
print_r ($curauth->user_favourite_post) ;
?>

... it returns with this...

Array
(
    [0] => 2387
    [1] => 1307
    [2] => 1149
    [3] => 1156
    [4] => 474
    [5] => 50
    [6] => 1131
    [7] => 1473
    [8] => 2388
    [9] => 2544
)

... which is all good. This is the post ID's that the user has 'Favorited'.

My question is, how can I display these posts on the author page? I have this...

    <?php
$my_query = new WP_Query();
$my_query->query(array( 'post__in' => array($curauth->user_favourite_post)));
while ($my_query->have_posts()) : $my_query->the_post(); 
?>

<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 
<?php endwhile; ?>

... But it just displays all of the posts and not the ones that have been 'Favorited' by the user. I've tried a number of different ways and they all just return every post.

share|improve this question
    
if you copied and paste the code, fix the user favourite _post in the second line, you are using user_favourite_post –  andresmijares25 Nov 17 '11 at 3:55
add comment

1 Answer

Could be because you are passing an array of array try this:

<?php
$my_query = new WP_Query();
$my_query->query(array( 'post__in' => $curauth->user_favourite_post));
while ($my_query->have_posts()) : $my_query->the_post(); 
?>
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 
<?php endwhile; ?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.