Title: WP_Query returning wrong result
Last modified: August 21, 2016

---

# WP_Query returning wrong result

 *  [bibigeon](https://wordpress.org/support/users/bibigeon/)
 * (@bibigeon)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/wp_query-returning-wrong-result/)
 * My plugin adds a custom post type to wordpress, and id like to display all posts
   that have been published. I use wp_query to display all posts but it seems to
   fetch all post regardless of their status. Have I forgotten something ?
 * Note that status changes from publish to draft, I use wp_update_post() to edit
   the post status . here is my code :
 * Loop :
 *     ```
       function jobs_list_loop() {
           global $paged;
           //$curpage = $paged ? $paged : 1;
           if ( get_query_var('paged') ) {
                               $paged = get_query_var('paged');
                       } elseif ( get_query_var('page') ) {
                               $paged = get_query_var('page');
                       } else {
                               $paged = 1;
                       }
           $args = array(
               'post_type' => 'job',
               'orderby' => 'ID',
               'posts_per_page' => POST_PER_PAGE,
               'post_status' => 'publish',
               'paged' => $paged
           );
           $query = new WP_Query($args);
           $curpage = $paged;
           if($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
           ?>
           <div id="post-<?php the_ID(); ?>" class="quote">
           <?php
           echo get_the_post_thumbnail($post->ID, array($image_width,$image_height));
           the_content();
           ?>
           </div>
           <?php
           endwhile;
               echo '
               <div id="wp_pagination">
                   <a href="'.get_pagenum_link(1).'">«</a>
                   <a> 0 ? $curpage-1 : 1)).'">‹</a>';
                   for($i=1;$i<=$query->max_num_pages;$i++)
                       echo '<a href="'.get_pagenum_link($i).'">'.$i.'</a>';
                   echo '
                   <a>max_num_pages ? $curpage+1 : $query->max_num_pages)).'">›</a>
                   <a>max_num_pages).'">»</a>
               </div>
               ';
               wp_reset_postdata();
           endif;
       }
       ```
   
 * Here is the code used to change status from publish to draft :
 *     ```
       $jb_post = array(
             'ID' => $id,
             'post_status' => 'draft'
         );
         wp_update_post( $my_post );
       ```
   
 * Note that if I change to query to fetch only drafts, or trash or whatever it 
   will do it successfuly. Am i forgetting something ? I have made tons of research
   and can’t find anything giving a suitable answer.
 * Thank you.

Viewing 1 replies (of 1 total)

 *  Thread Starter [bibigeon](https://wordpress.org/support/users/bibigeon/)
 * (@bibigeon)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/wp_query-returning-wrong-result/#post-4676852)
 * `wp_update_post( $my_post );` is maent to be `wp_update_post( $jb_post );`, I
   made a mistake while editing teh code straight from teh text box…
 * It obviously makes no difference, I still got the same issue

Viewing 1 replies (of 1 total)

The topic ‘WP_Query returning wrong result’ is closed to new replies.

## Tags

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

 * 1 reply
 * 1 participant
 * Last reply from: [bibigeon](https://wordpress.org/support/users/bibigeon/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/wp_query-returning-wrong-result/#post-4676852)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
