Wordpress query

Hi Guys,

wondering if you can help me figure this out

im trying to sort posts on a category page

this is the loop im using

<?php
/**
 * The loop that displays posts.
 *
 */
?>

<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
	<div id="nav-above" class="navigation">
		<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
		<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
	</div><!-- #nav-above -->
<?php endif; ?>

<?php /* If there are no posts to display, such as an empty archive page */ ?>
<?php if ( ! have_posts() ) : ?>
	<div id="post-0" class="post error404 not-found">
		<h1 class="entry-title"><?php _e( 'Not Found', 'twentyten' ); ?></h1>
		<div class="entry-content">
			<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyten' ); ?></p>
			<?php get_search_form(); ?>
		</div><!-- .entry-content -->
	</div><!-- #post-0 -->
<?php endif; ?>

<?php
	/* Start the Loop.
	 *
	 */ ?>

<?php query_posts($query_string . '&meta_key=eventdate&orderby=meta_value&order=asc' ); ?>
<?php while ( have_posts() ) : the_post(); ?>


<?php /* How to display all other posts. */ ?>
<div class="cat-list">
<li>
		<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

		
			<div class="entry-content">
            	<?php the_post_thumbnail(); ?>
				<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
				<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
			</div><!-- .entry-content -->

		</div><!-- #post-## -->
</li>
</div>


<?php endwhile; // End the loop. Whew. ?>

<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if (  $wp_query->max_num_pages > 1 ) : ?>
				<div id="nav-below" class="navigation">
					<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
					<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
				</div><!-- #nav-below -->
<?php endif; ?>

i am using this line <?php query_posts($query_string . ‘&meta_key=eventdate&orderby=meta_value&order=asc’ ); ?>
to sort the posts, however this line seems to query all the posts and not just the posts within the current category, so it shows posts in all categorys

i would like this to just display posts within the current category, can someone help me out with this?

thanks :slight_smile:

As far as I remember, using query_posts means WP retrieves the posts again from the database using your new criteria, so it would not bother about the category unless you tell it to.

hi i know how to query posts in a particular cat but how do i query posts depending on the category the user is viewing?

Maybe this?: http://codex.wordpress.org/Function_Reference/get_query_var

im trying to use something like this, its not working though

$category_id = get_query_var('cat');
query_posts('$category_id&meta_key=eventdate&orderby=meta_value&order=asc' ); ?>

Try


$category_id = get_query_var('cat');
query_posts('cat=' . $category_id . '&meta_key=eventdate&orderby=meta_value&order=asc' ); ?>  

your a genius, thanks that worked :smiley: