Monday, February 6, 2023
HomeWordPress Developmentcapabilities - The best way to type posts alphabetically primarily based on...

capabilities – The best way to type posts alphabetically primarily based on a particular dad or mum class


You should utilize the next code snippet to type posts alphabetically primarily based on a particular dad or mum class in WordPress:

<?php 
$parent_cat="Mother or father Class Identify"; 
$parent_cat_id = get_cat_ID($parent_cat); 
$args = array(
 'category__in' => array($parent_cat_id),
 'orderby' => 'title', 
 'order' => 'ASC', 
 'posts_per_page' => -1
);
$question = new WP_Query( $args );
if ( $query->have_posts() ) {
 whereas ( $query->have_posts() ) {
   $query->the_post();
   the_title();
   echo '<br>';
 }
 wp_reset_postdata();
} else {
 // no posts discovered
}
?>

Within the code, substitute “Mother or father Class Identify” with the precise identify of the dad or mum class you need to type posts from. The code will retrieve all of the posts beneath this class, type them alphabetically primarily based on the submit title, and show the title of every submit.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments