admin管理员组

文章数量:1125785

I need all auto-generated category pages to sort oldest-to-newest

I'm editing my "All Archives" template in block editor but I'm not having any success

it contains a query loop with "inherit query from template" checked, and turning this off is not an option because it's a template used by all categories and if turned off I won't get the correct content on the correct pages

however, having this option checked also prevents changing the sort order

all the solutions I find online say to edit the theme's archives.php, however, this is a file that only exists in legacy themes and I'm using a modern theme

my theme does have an archives.html containing the following line:

<!-- wp:query {"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true},"tagName":"main"} -->

I changed desc to asc, cleared WP-Optimize cache, cleared Redis cache, cleared Cloudflare cache, restarted PHP-FPM, restarted Apache, restarted MySQL, restarted Redis, then cleared WP-Optimize and Redis caches again, ran a WP-Optimize database cleanup, restarted PHP/Apache/MySQL/Redis again, and then cleared all caches again. However, there was no change.

I need all auto-generated category pages to sort oldest-to-newest

I'm editing my "All Archives" template in block editor but I'm not having any success

it contains a query loop with "inherit query from template" checked, and turning this off is not an option because it's a template used by all categories and if turned off I won't get the correct content on the correct pages

however, having this option checked also prevents changing the sort order

all the solutions I find online say to edit the theme's archives.php, however, this is a file that only exists in legacy themes and I'm using a modern theme

my theme does have an archives.html containing the following line:

<!-- wp:query {"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true},"tagName":"main"} -->

I changed desc to asc, cleared WP-Optimize cache, cleared Redis cache, cleared Cloudflare cache, restarted PHP-FPM, restarted Apache, restarted MySQL, restarted Redis, then cleared WP-Optimize and Redis caches again, ran a WP-Optimize database cleanup, restarted PHP/Apache/MySQL/Redis again, and then cleared all caches again. However, there was no change.

Share Improve this question asked Jan 27, 2024 at 17:14 Displayname71Displayname71 1132 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Given your detailed description, it seems you've taken several steps to address the issue of sorting your archive pages in WordPress. The fact that changing the "order":"desc" to "asc" in the archives.html file of your theme didn't yield the desired result suggests a deeper issue.

Try this in your functions.php file:

function wpb_modify_category_query( $query ) {
    if ( $query->is_category() && $query->is_main_query() ) {
        // Set the order to ASC
        $query->set( 'order', 'ASC' );
    }
}
add_action( 'pre_get_posts', 'wpb_modify_category_query' );

本文标签: themesquery loop quotinherit query from templatequot prevents setting sort order