It’s fairly simple to add it manually for your categories, If you want to be able to set and store the sort order from the admin UI, that’s a bit more involved.
a manual fix can be achieved with a pre_get_posts
hook:
function wpa55535_pre_get_posts( $query ){
// if this is a category page
if( $query->is_category ):
// if cat = 1, set order to ASC
if( $query->query_vars['cat'] == 1 ):
$query->set( 'order', 'ASC' );
// if cat = 2, set order to DESC
elseif( $query->query_vars['cat'] == 2 ):
$query->set( 'order', 'DESC' );
endif;
endif;
return $query;
}
add_action( 'pre_get_posts', 'wpa55535_pre_get_posts' );
If you’re using ‘pretty’ permalinks you’ll have to check for category_name
instead of cat
, as it’s queried by name not ID in that case.
Related Posts:
- Different post sort order within different categories
- How to sort posts by last name (2nd word) on ONE category only?
- How to sort posts alphabetically based on a specific parent category
- How to Change Order of Posts in Admin?
- Setting Custom Sort Order of Posts within a Category
- Query posts from current year
- Display posts in alphabetical order for a particular category
- How to sort posts inside categories
- how to get post order by post id wp_query?
- Sort by last word in title
- How to list post as buch of category, and all of them
- Sort Posts Alphabetically Based on Specific Category (Divi)
- Get Posts Under Custom Taxonomy
- How to display related posts from same category?
- Get current menu_order
- How to show related posts by category
- How to add category to: ‘wp-admin/post-new.php’?
- Including categories in search results
- Use category base slug in posts’ permalink
- Random sort within an already sorted query
- Count how many posts in category
- Custom Single Post By Category
- How to get the number of posts in a selected category?
- MySQL Query to Retrieve Category from wp_posts
- what types of order can I pass to get_posts() via orderby?
- Different number of posts in each category
- Display all posts from specific categories on a page
- Can I force a metabox to be in one column?
- Display the latest post from a category in a page
- Sort posts by popularity/page views
- How to show list of posts by author and category?
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- How to Group Posts by the First Letter or Number?
- Category checkbox list tree changes when editing a post
- How to Arrange Posts by Size in the WordPress Dashboard?
- How do I reorder (pop and push) items from WP_Query?
- How to add metabox for post of specific category
- Convert custom fields to post categories
- How to put last edited entry on top of the blog-post list?
- blog posts sorting doesnt work while using get_query_var
- Manipulate post category after time
- Show related posts by category but ignore one category
- Sort post by attributes ‘order’
- Sort posts by tags in category pages
- How to disable Uncategorized category URL?
- Add role that restricts user to post in specific category
- How to get Category Id from Post Id ?
- Group Posts by First Letter of Title
- Count posts in category including child categories
- Getting Position of a post in a category
- Display only posts from a specific parent category
- Reverse chronology of post listing
- How can I custom order the results from wp_list_categories?
- How to control which category will be picked for the slug of a post?
- Categories box not showing on post edit pages
- How can I get on the same row two post of different categories?
- Polylang – display one post into 3 categories with different lang [closed]
- How to make category for word post_content
- How to sort the post to a specific category
- Listing category and its posts one by one
- Print out one of 2 post category [closed]
- How to get if category has posts?
- Show some texts in posts belonging to Specific category
- Custom Admin Post Column change order
- Export Posts Without Categories In An XML File
- wordpress category Description not allowed tag
- View post with specific category id and name which I selected in the backend (drop-down option)
- Filter/Sort Post Form On Taxonomy page
- Site ‘Categories’: save an admin global setting with post metadata [closed]
- How can I fixe the article title problem?
- Automatically select category based on user role
- Filters do not work when there are multiple (one works)
- I have a blog and want to prompt the user to select a category they like and have that select a random blog post
- How to remove category and other tags from posts page
- I have a website issue I am trying to resolve
- Get the category of post from which category page it have been clicked
- How to get a list of all posts and their categories?
- Show category name in category.php when posts assigned to multiple categories
- Category and archive issue
- Error counting posts of category
- Adding content to the top of post’s based on their category
- Show posts assigned to multiple categories in current category page
- WordPress converting ‘ to ’ and – to –?
- Add a category to posts, that DO NOT contain two specific keywords?
- Menu for all posts from multiple categories
- How to display related posts from the same category?
- How to show related posts by detecting the current category?
- Display posts on a custom page from only a specific category?
- How can I change the post order after filtering in WordPress?
- Preset category checkbox from URL parameter when creating new post
- What is the best way to publish News articles?
- WordPress menu disappears in category pages
- How to specify a post category for the home (posts) page?
- Unable to create categories and tags for posts in wordpress multisite
- Exclude the Newest Recent Post from their Category After New post Publish old post should be in their category at Home Page
- Menu item on a category
- Display posts from a specific category on frontpage.php template?
- Mismatch between posts count and actual list in admin posts page
- Order by Post Title in WP Query not working
- How to display blog posts per category using tabs or accordion?