开发者

Wordpress - displaying specific posts with wp_query

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 re开发者_C百科turn every post.


Try

$my_query->query( array( 'post__in' => (array) $curauth->user_favourite_post ) );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜