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

Sorting Users page admin column with ACF field

You can use the “pre_user_query” filter hook to modify the query that retrieves the users. Here’s an example code that how to sort the Users page admin column with an ACF field named. function sort_users_by_acf_field( $query ) { if ( ! is_admin() ) { return; } if ( isset( $query->query_vars[‘orderby’] ) && ‘user_company_name’ === $query->query_vars[‘orderby’] … Read more