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)
- how to show comments only author which send own posts in wordpress
- ACF date picker to trigger category change
- shortcode // get posts by ids
- Is there a way to categorize a list posts all at once?
- Get category slug of the Parent category of a Product
- How to put the author of the post in the comments?
- How to get tags when using publish_post
- Check if almost 10 year old – working code is up to date
- Yoast breadcrumb URL shows category instead of the page
- Alt text attributes not showing over portfolio images
- Show single post child category from a determined parent
- Author post count in category
- Order column custom date using pre_get_posts
- How can I create a ‘sub-blog’ which has its own sidebar on individual posts?
- Featured Story Shortcode not outputting content
- I want to add the 10 most recent posts under a parent category on the main menu
- Find most used words in post titles
- WordPress Sticky Post Count “Fix” Breaking Pagecount by 72 pages!
- $post->post_content empty while all other properties are correct
- Function is printing twice – any suggestions?
- How to sort WP_Post Object array by object field in php?
- How to add class to specific navbar item when post parent category is in specific category
- sort title descending with title with number
- exclude particular category in api
- On the online version of my blog posts disappear
- How to add a custom class attribute into code wrapper? [duplicate]
- How to Create another Page Category like the “Post” and “Pages”
- Current post categories and subcatecories outside of the loop
- How do you change the permalink for posts for a single category?
- Query prints posts without specific categories
- Foreach issue in get_posts function
- Posts are not displaying on their category and tag page
- Make categories appear random
- how to filter posts by category without page load (ajax) in wordpress?
- Does having category name in permalinks affect SEO when having a post in multiple categories?
- How to increase the number posts that displays by a hierarchical taxonomy? (HTTP ERROR 500)
- query posts with selected post ids first
- How to add a ‘News’ section to specific posts in WordPress
- how to create a category with wp_insert_post and post_category
- Get Category in save_post Hook
- Remove pagination if search returns empty
- Remove HTML tags from all posts
- Set a post expiration and delete a post when expirate
- How to 301 redirect from url with post id to permalink with post name (slug)?
- Create/Set Category as Title of Post
- How to distinguish pages created by woocommerce?
- Exclude posts in a category on one page but show those posts on a different page
- How to create a button to filter posts (list) by meta value
- Why do I have categories with duplicate slugs?
- How to display related post from same category in single.php
- WordPress the_category(); only works with message-posts not with project posts, how do I specify project categories?
- Is there a way to save different data when USER interacts with the same POST?
- How to add a block to a category page?
- Sorting post by custom field and category
- How to display particular categorie’s post which associated to specific user?
- Display Specific Categories posts on the home page
- I want to change the WordPress comments file
- Replace Tag Keyword With Link Within Post Content
- Excluding tag Link from html tags in Post content
- Excluding category from post navigation in WordPress?
- I want to show recent post according to category of the post in single.php?
- Using Orderby and meta_value to order natural/alphanumerical
- Limit amount of categories displayed in a post
- How to make a page show posts only from specific categories without editing php files
- show image gallery in archives or category page
- show only one category and filter by tag
- Page with Category Returning 1
- Automatic Table of contents with categories and posts
- How to sort (orderby) a query done by a template function before the ‘foreach’ loop?
- Code to display random ordered posts in Categories across pages [duplicate]
- More Than 50K Categories and WordPress Admin Panel Stop Showing Categories and Posts