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 1 year, 6 months ago.

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

    dwzemens
    Participant
    Post count: 5

    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' ) );
    }
    }


    1955Design
    Web + WordPress

    #21239

    cehwitham
    Participant
    Post count: 396

    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.

    http://wordpress.stackexchange.com/questions/50761/when-to-use-wp-query-query-posts-and-pre-get-posts

    http://wp.smashingmagazine.com/2013/01/14/using-wp_query-wordpress/

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

    Chris


    Twitter: cehwitham Web: cehwitham.com

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

You must be logged in to reply to this topic.