Question

I would like to sort my post in specyfic category ASC by date. My code is:

<?php $cat_id = 3; //the certain category ID
$latest_cat_post = new WP_Query( array('posts_per_page' => 4, 'category__in' => array($cat_id)));
if( $latest_cat_post->have_posts() ) : while( $latest_cat_post->have_posts() ) : $latest_cat_post->the_post();  ?>
<?php the_post_thumbnail('thumbnail', array('class' => 'thumbnailmini')); ?>
<h3><?php the_title(); ?></h3>  
<?php the_content('więcej ->'); ?>
<div class="clear"></div>
<?php endwhile; endif; ?>

This code display 4 posts from category "3". How to sort this posts? I found:

<?php query_posts ('cat=3&orderby=date&order=ASC'); ?>

but it doesn't work.

Regards.

Was it helpful?

Solution

try this,,

<?php $cat_id = 3; //the certain category ID
$latest_cat_post = new WP_Query( array('posts_per_page' => 4,'orderby' => 'date','order' => 'ASC', 'category__in' => array($cat_id)));
if( $latest_cat_post->have_posts() ) : while( $latest_cat_post->have_posts() ) : $latest_cat_post->the_post();  ?>
<?php the_post_thumbnail('thumbnail', array('class' => 'thumbnailmini')); ?>
<h3><?php the_title(); ?></h3>
<?php the_content('wiecej ->'); ?>
<div class="clear"></div>
<?php endwhile; endif; ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top