Sort by multiple columns using get_posts
$args = array( ‘post_type’ => ‘event’, ‘meta_key’ => ‘start_date’, ‘meta_type’ => ‘DATE’, ‘orderby’ => array( ‘start_date’ => ‘ASC’, ‘menu_order’ => ‘ASC’, ) ); $posts = get_posts( $args );
$args = array( ‘post_type’ => ‘event’, ‘meta_key’ => ‘start_date’, ‘meta_type’ => ‘DATE’, ‘orderby’ => array( ‘start_date’ => ‘ASC’, ‘menu_order’ => ‘ASC’, ) ); $posts = get_posts( $args );
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
Custom product sorting archive page
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
What is wrong with my sorting logic?
Sorting by Title for Post Archive Categories for Custom Post Type
Sort by price when price is set in multiple keys
pre_get_posts is an action hook used for modifying the arguments passed to the WP_Query class, and if you’re filtering the posts in the list table at wp-admin/edit.php, then yes, you would use that hook. However, since you’re filtering the terms in the list table at wp-admin/edit-tags.php, then the hook that you should have used is … Read more
Woocommerce backend sorting product drag drop by menu_order to date
Sort posts by Date (DESC) and by ACF: active_inactive (ASC)