1

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.

1
  • if you copied and paste the code, fix the user favourite _post in the second line, you are using user_favourite_post Commented Nov 17, 2011 at 3:55

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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