[wp-trac] [WordPress Trac] #60963: Custom query, inherit main query, show scheduled posts

WordPress Trac noreply at wordpress.org
Mon Apr 8 21:13:40 UTC 2024


#60963: Custom query, inherit main query, show scheduled posts
-------------------------------+-----------------------------
 Reporter:  stefacchio         |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:  6.5
 Severity:  major              |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 Hi,
 I created a custom query inheriting the main WP query, so my custom query
 has custom 'paged' args and others args are the same of the main query.
 The problem is that the main query works fine, instead my WP query also
 show the Scheduled posts.
 I debugged the args and are the same, I think there is a bug.

 Here my code to explain better:

 functions.php
 {{{#!php
 <?php
 global $wp_query;
 wp_localize_script( 'ajax-frontend', 'ajaxfrontendobject', array(
                         'ajaxurl' => admin_url( 'admin-ajax.php' ),
                         'query_vars' => json_encode( $wp_query->query_vars
 ),
                         'security' => wp_create_nonce( 'get_posts_by_ajax'
 ),
                   ));

 }}}
 }}}

 functions.php
 {{{#!php
 <?php
 add_action( 'wp_ajax_nopriv_ajax_pagination_get_posts',
 'luxuryconcept_get_posts_by_ajax' );
 add_action( 'wp_ajax_ajax_pagination_get_posts',
 'luxuryconcept_get_posts_by_ajax' );

 if ( ! function_exists( 'luxuryconcept_get_posts_by_ajax' ) ) {
         function luxuryconcept_get_posts_by_ajax() {
                 check_ajax_referer('get_posts_by_ajax', 'security');

                 $args = json_decode( stripslashes( $_POST['query_vars'] ),
 true );
                 $args['paged'] = $_POST['page'];
                 query_posts( $args );


             echo "<br><br> ajax:" .
 print_r($GLOBALS['wp_query']->query_vars);


                 get_template_part( 'templates/loop', 'index' );

                 die();
         }
 }
 }}}

 JS

 {{{
 $.ajax({
                         url: ajaxfrontendobject.ajaxurl,
                         type: 'post',
                         data: {
                                 action: 'ajax_pagination_get_posts',
                                 security: ajaxfrontendobject.security,
                                 query_vars: ajaxfrontendobject.query_vars,
                                 page: page
                         },
 }}}


 Thanks

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60963>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list