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)
Viewing 1 replies (of 1 total)
- The topic ‘WP_Query returning wrong result’ is closed to new replies.