WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] query in sidebar conflicting with main query on page (2 posts)

  1. Skeary
    Member
    Posted 1 year ago #

    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..

    <?php
    			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; ?>
    				</select>
    			<?php endif; ?>
    			<?php wp_reset_postdata(); ?>
  2. Skeary
    Member
    Posted 1 year ago #

    Looks like get_posts() was the way to go.

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.