Unable to reset global query – help need

Community Forums Forums Design Tips and Tricks Unable to reset global query – help need

This topic is: not resolved

This topic contains 1 reply, has 2 voices, and was last updated by  cehwitham 2 years, 9 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #14215


    I am trying to use the code below in functions.php with the goal of querying the database for one category. Works like a charm. I also am using code in the genesis_after_loop to reset the query via wp_reset_query(). Problem is the query is not being reset.

    Can anyone shed some light on how I can reset the global query after the code below runs?

    Thanks very much.

    add_action('genesis_before_loop', 'dwz_staff_custom_fields_before_loop');
    function dwz_staff_custom_fields_before_loop ()
    global $query_string;
    $wp_query = null;
    // http://codex.wordpress.org/Function_Reference/query_posts
    if( is_page(9781) OR is_category(43) ) // Meet Our Staff page as well as category archive page
    query_posts( array( 'category__and' => array(43), 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC' ) );

    Web + WordPress



    You would be better rewriting this to use the WP_query object rather than using query_posts. This will avoid having to reset the loop.

    The two articles below will provide more information and pointers of how to do this.



    I hope that’s useful. Let me know if you need more assistance with this.


    Twitter: cehwitham Web: cehwitham.com

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.