Support » Themes and Templates » query in sidebar conflicting with main query on page

  • Resolved Skeary


    I have this in my sidebar.php and it works, except that it overwrites the main query of the page and every time I just get the archive for the newsletter category. How can I stop it from doing that? What is the recommended way to get that data without interrupting the main loop? Do I need to use a wpdb query? seems like it shouldn’t need that..

    			query_posts( 'category_name=newsletter' );
    			if ( $wp_query->have_posts() ) : ?>
    				<select id="newsletter-dropdown" name="newsletter-dropdown">
    				<option value="">Newsletter Archives</option>
    				<? while ( have_posts() ) : the_post(); ?>
    					<option value="<?php the_permalink(); ?>"><?php the_title(); ?></option>
    				<?php endwhile; ?>
    			<?php endif; ?>
    			<?php wp_reset_postdata(); ?>
Viewing 1 replies (of 1 total)
  • Looks like get_posts() was the way to go.

    I would have rather gone by category name, but this will have to do.

Viewing 1 replies (of 1 total)
  • The topic ‘query in sidebar conflicting with main query on page’ is closed to new replies.