How to sort posts alphabetically based on a specific parent category

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 ( … Read more

How to remove slug from CPT correctly?

This is a two-step process. First, you need to remove the slug from the default URL. (use a unique slug while registering the CPT). function wpse413969_remove_cpt_slug( $post_link, $post ) { if ( $post->post_type == ‘YOUR_CPT’ && $post->post_status == ‘publish’) { $post_link = str_replace( “https://wordpress.stackexchange.com/” . $post->post_type . “https://wordpress.stackexchange.com/”, “https://wordpress.stackexchange.com/”, $post_link ); } return $post_link; } … Read more