The value of the variable $numbers is 1, 2, 3, 4, 5 but this code doesn't work: $wp_query->query(array('post__in'=>array($numbers),'showposts'=>5,'paged'=>$paged)); PHP: When I type those numbers manually it works: $wp_query->query(array('post__in'=>array(1, 2, 3, 4, 5),'showposts'=>5,'paged'=>$paged)); PHP: What is the problem?
so $numbers is a string containing the text "1, 2, 3, 4, 5"? If so, what you're doing is creating an array with a string in it, not what you wanted. To accomplish that, simply do explode(', ', $numbers) instead: $wp_query->query(array('post__in'=> explode(', ', $numbers),'showposts'=>5,'paged'=>$paged)); PHP:
This code doesn't seem to work... Here is how I get the $numbers string: <?php $post_ids = $wpdb->get_col("SELECT comment_post_ID FROM $wpdb->comments WHERE user_id = $current_user->ID AND comment_approved = '1' "); $numbers = implode(', ', $post_ids); ?> PHP: The first line gets IDs from database and the second line adds , symbol in order to use these numbers as an array argument. Is anything wrong?
You don't need to do the implode, remove that line and just do: $wp_query->query(array('post__in'=> $post_ids,'showposts'=>5,'paged'=>$paged)); PHP: And if that doesn't work do: echo "<pre>"; print_r($post_ids); echo "</pre>"; PHP: and show us the output as I'm not sure how wordpress returns the db results.