Title: query posts by post ID variable
Last modified: August 21, 2016

---

# query posts by post ID variable

 *  Resolved [luke.faragher](https://wordpress.org/support/users/lukefaragher/)
 * (@lukefaragher)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/query-posts-by-post-id-variable/)
 * Hi really struggling with something I thought would be quite straightforward 
   and hoping that some one can help…
 * I essentially need to query posts by a list of post ID which are stored and then
   retrieved in a custom table in my database.
 * Current Code…
 *     ```
       <?php
       $block = $wpdb->get_results( "SELECT sid FROM wp_entries WHERE uid = '$current_user->ID'" , ARRAY_N);
   
       	print_r ($block);
   
          $args = array('cat' => 8, 'showposts' => 3, 'post__not_in' => array($block) );
          $category_posts = new WP_Query($args);
   
          if($category_posts->have_posts()) :
             while($category_posts->have_posts()) :
                $category_posts->the_post();
       ?>
       ```
   
 * Unfortunately all i’m getting back for this is the printed array …
 * `Array ( [0] => Array ( [0] => 835 ) [1] => Array ( [0] => 832 ) [2] => Array([
   0] => 823 ) )`
 * But the posts are still displaying??
 * Im fairly sure that i’m missing something fundamental but have no idea where 
   to start.
 * Thank you in advance for any help

Viewing 1 replies (of 1 total)

 *  Thread Starter [luke.faragher](https://wordpress.org/support/users/lukefaragher/)
 * (@lukefaragher)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/query-posts-by-post-id-variable/#post-3739850)
 * Solved it for anyone else who might find this useful…
 *     ```
       //This is the query that gets the blocked Post IDs
   
       		$things = array();
       		$results = $wpdb->get_results( "SELECT sid FROM wp_entries WHERE uid = '$current_user->ID'");
       		foreach( $results as $result )
       		$things[] = $result->sid;
   
       //This is the query that blocks the posts
   
          $args = array('cat' => 8, 'showposts' => 3, 'post__not_in' => $things );
          $category_posts = new WP_Query($args);
   
          if($category_posts->have_posts()) :
             while($category_posts->have_posts()) :
                $category_posts->the_post();
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘query posts by post ID variable’ is closed to new replies.

## Tags

 * [db-query](https://wordpress.org/support/topic-tag/db-query/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [luke.faragher](https://wordpress.org/support/users/lukefaragher/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/query-posts-by-post-id-variable/#post-3739850)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
