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.
1 Answer
Reset to default 0Given 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
版权声明:本文标题:themes - query loop "inherit query from template" prevents setting sort order 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736674131a1947085.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论