WordPress分类文章排序异常:PHP代码修改咨询(4.5版本)
Fixing WordPress 4.5 Category Page Sorting (Oldest Posts First Instead of Newest)
Hey there! I’ve run into this exact issue before with older WordPress versions—let’s get your category page showing the newest posts first again.
First, Check Your Theme’s Template Files
WordPress uses category.php (or archive.php if category.php doesn’t exist) to render category pages. Someone might have added custom query code that overrides the default sorting.
- Open your theme’s
category.phpfile (via FTP or WordPress Dashboard > Appearance > Theme Editor). - Look for lines that use
query_posts()ornew WP_Query(). You might see something like this:query_posts( array( 'category_name' => 'berita-terkini', 'order' => 'ASC', // This is the culprit! 'orderby' => 'date' ) ); - Change the
orderparameter fromASC(ascending, oldest first) toDESC(descending, newest first):'order' => 'DESC'
If you don’t find query_posts in category.php, check archive.php next—some themes use this as a fallback for all archive-type pages (including categories).
If No Luck in Template Files, Check functions.php
Many themes and customizations use the pre_get_posts hook to modify query parameters globally. This is another common spot for sorting overrides:
- Open your theme’s
functions.phpfile. - Search for a function hooked to
pre_get_poststhat targets category pages. It might look like this:function custom_category_sort_order( $query ) { if ( $query->is_category() && $query->is_main_query() ) { $query->set( 'order', 'ASC' ); // This forces oldest first } } add_action( 'pre_get_posts', 'custom_category_sort_order' ); - Either change
ASCtoDESChere, or delete the entire function if you don’t need custom sorting (WordPress defaults to newest posts first for categories).
Quick Notes
- Always back up your theme files before making changes—just in case something goes wrong!
- If you still can’t find the code, it might be a plugin overriding the sort order. Try disabling plugins one by one to test, but since you asked about modifying PHP code, the above spots are the most likely culprits.
内容的提问来源于stack exchange,提问作者gumuruh
相关产品推荐
相关产品推荐

