简体   繁体   English

如何在 WordPress 中按字母顺序对类别帖子进行排序?

[英]How to sort category posts alphabetically in WordPress?

Sorry about that but I can't figure out what's wrong with my code.很抱歉,但我无法弄清楚我的代码有什么问题。
I am trying to sort my posts from category #3 alphabetically but I think I'm doing it wrong.我正在尝试按字母顺序对类别 #3 中的帖子进行排序,但我认为我做错了。

<?php
    $catquery = new WP_Query( 'cat=3' );
    while($catquery->have_posts()) : $catquery->the_post('&orderby=title&order=ASC');
?>

Try this:尝试这个:

<?php

$args = array(
    'posts_per_page' => -1,
    'cat' => 3
    'orderby' => 'title',
    'order' => 'DESC'
);

    $catquery = new WP_Query($args);
    while($catquery->have_posts()) : $catquery->the_post();
?>

Hope help you.希望能帮到你。

try sort from query itself尝试从查询本身排序

$args = [
            'order' => 'ASC',
            'orderby' => 'title',
        ];

        $query = new WP_Query($args);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM