M
M
mrWan2018-02-01 19:54:57
WordPress
mrWan, 2018-02-01 19:54:57

Issue with sorting asc in wp_query/query_posts in WordPress. What could be the problem?

This is how I post:

<? foreach (query_posts("cat=" . $value->cat_ID . '&orderby=title&order=ASC') as $post):

This method displays only 4 posts, if you remove the sorting or put instead of asc desc, then all posts are displayed. The same goes for wp_query. wp version latest

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2018-02-02
@Alex-Woo

query_posts() is for WordPress itself and should be used to modify the main WordPress Loop, if you need to create another loop then use get_posts() or WP_Query.

$args = array(
  'cat' => $value->cat_ID,
  'orderby' => 'title',
  'order' => 'ASC',
  'posts_per_page' => 3
);
$lastposts = get_posts( $args );
foreach( $lastposts as $post ){

}
wp_reset_postdata();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question