D
D
Dmitry Grabko2018-02-06 11:24:40
WordPress
Dmitry Grabko, 2018-02-06 11:24:40

How to sort posts in WP?

Posts on the page are displayed as follows

<div class="uk-grid uk-grid-collapse vtop">
    <?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    $posts = query_posts(array('cat'=>$category_id,'posts_per_page'=>'9','order'=>'DESC','paged'=>$page));?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); // если посты есть - запускаем цикл wp ?>
    <?php get_template_part('template/loop','product'); // для отображения каждой записи берем шаблон loop.php ?>
    <?php endwhile;?>
    <?php endif;?>   
  </div>

I add a sort field to the line, but there is no result
$posts = query_posts(array('cat'=>$category_id,'posts_per_page'=>'9','orderby' => 'title', 'order' => 'DESC','paged'=>$page));?>

Also, when replacing query_posts with get_posts , only 1 record is displayed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TheRevan, 2018-02-06
@TheRevan

query_posts seems to take a string and not an array, with a separator &, and in get_posts you need to add posts_per_page to increase the limit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question