• Resolved luke.faragher

    (@lukefaragher)


    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

    (@lukefaragher)

    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.