You can use the following code snippet to sort posts alphabetically based on a specific parent category in WordPress:
<?php
$parent_cat="Parent Category Name";
$parent_cat_id = get_cat_ID($parent_cat);
$args = array(
'category__in' => array($parent_cat_id),
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => -1
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
the_title();
echo '<br>';
}
wp_reset_postdata();
} else {
// no posts found
}
?>
In the code, replace “Parent Category Name” with the actual name of the parent category you want to sort posts from. The code will retrieve all the posts under this category, sort them alphabetically based on the post title, and display the title of each post.
Related Posts:
- Different post sort order within different categories
- How to sort posts by last name (2nd word) on ONE category only?
- How to choose a sort order (for posts) per category? (ideally when creating a new category)
- How to Change Order of Posts in Admin?
- Setting Custom Sort Order of Posts within a Category
- Query posts from current year
- List only child categories a post is in, of a specific parent category
- Limit function to specific post category
- How can I list random authors from current post category?
- Display posts in alphabetical order for a particular category
- Add icon/badge next to posttitle of specific category
- Show Primary Category first when I display post categories
- Exclude category from
- How to allow users to post only in certain category and hide elements from edit page?
- How to sort posts inside categories
- Order posts alphabetically: how to set order=asc in mysql query?
- how to get post order by post id wp_query?
- Sort by last word in title
- Un-highlight Blog Menu Item when Category Menu Item is Selected
- How to list post as buch of category, and all of them
- How to add content above footer in posts from specific category
- get category in list of posts // shortcode for custom related posts
- Save All Post Permalink From A Specific Category into a .txt file
- AJAX load more posts not using correct category and repeating the same few posts
- How to sort custom post’s category by id from the theme’s function.php?
- Show only top 3 posts from 3 categories in order on home page
- How do we display a certain category type on a page while hiding all others?
- Sort Posts Alphabetically Based on Specific Category (Divi)
- Filters do not work when there are multiple (one works)
- Including categories in search results
- Count how many posts in category
- Custom Single Post By Category
- How to Group Posts by the First Letter or Number?
- Code to auto expire posts after 30 days
- Show One Category on Post
- Custom colors for post rows based on post meta value
- Order post by year DESC and month ASC
- What Defines What Category A Post Picks (if in multiple)
- Delete Post From Front-End and attachment permanently
- Show all post titles
- Function to show random posts from a category
- Add Category name to Post Title (h1)
- Posts are not showing up on particular category
- Change Order of Admin Posts Depending on Meta
- How to display related posts by subcategory and not parent category
- Uppercase first sentence in every post
- Display post category in foreach loop with category link
- Extracting post categories
- How can I sort posts by the date and a custom meta field?
- How to limit posts by category
- How to redefine the sorting of product categories by menu_order?
- Force the “Choose from the most used tags” meta box section to always be expanded
- Get user categories with most posts in it
- How to list recent posts in a wp nav menu?
- How to display posts via custom taxonomy terms using checkboxes?
- Dynamic dependent Dropdown lists for categories, sub-categories and posts
- How to display two blog categories as separate sections on one page?
- why does wordpress ignore the post args?
- get posts from Custom Post Type & Category
- How can I add a box to edit Order on a regular post?
- Defined function isn’t showed on page
- How to enable custom Shortcodes in Post Category Description? [duplicate]
- WordPress 302 Redirect to Random Product/Post/Page
- How to call posts under a specific category on static front page?
- Add code to a specific post’s content
- Give posts a particular template based on the assigned category
- Optimize CPT-function with a loop
- Post-Archive like a page in a specific subdirectory
- How to display only one category in a custom post type?
- Get only X number of categories
- inserting a category into post
- Making a wordpress page print friendly
- latest post showing up twice on posts page
- wp_list_categories() Exclude All Categories Except One
- Different post views for different category views
- Possible?! A contextually titled back link
- Allow / show post comments in category pages
- How to select a category automatically based on a word in WordPress post title?
- I need to create “View Profile” and “Edit Profile” links by incorporating the Post Title/ID, but can’t seem to manage it
- How display related post only in Default category on single
- How to add class to specific navbar item when post parent category is in specific category
- Posts are not displaying on their category and tag page
- how to create a category with wp_insert_post and post_category
- Exclude posts in a category on one page but show those posts on a different page
- How to add a block to a category page?
- Sorting post by custom field and category
- Post Category link is same with Page link
- Show custom post category for single post
- Get a list of categories that are related to posts
- Need help writing loop to display posts by categories in separate divs
- Query post category & remove any post id
- Multiple Post Repeat for Related Post Loop by Category
- How to edit label_submit styling?
- How to limit the number of results for all query_posts on mysite
- how to show posts on different pages if number of post per page is one
- Is possible to create a custom link that creates a post that’s already categorized?
- User driven content problems
- Is it possible to have different header style blog titles in different categories?
- How to display subcategory articles in the category view?
- Custom Admin Post Column change order