Query ‘orderby’ when there are multiple values for the same meta_key

Sorting by multiple meta keys (ref) may be helpful (untested): add_action( ‘pre_get_posts’, function ( \WP_Query $query ) { $orderby = $query->get( ‘orderby’ ); if ( ‘start_date’ === $orderby || ‘end_date’ === $orderby ) { $meta_query = array( ‘relation’ => ‘OR’, ‘meta_query_1’ => array( ‘key’ => $orderby, // start_date or end_date ), ‘meta_query_2’ => array( ‘key’ … Read more

How to sort a non-meta field in the User Admin Panel?

The WP_User_Query::parse_orderby() actually supports sorting by the number of posts, but because WP_User_Query::parse_orderby() limits by what users can be sorted, accomplishing a custom sort is a bit of a hack. Here’s the workaround I’ve created (semi-tested): add_filter( ‘manage_users_sortable_columns’, static function ( $columns ) { $columns[‘articles_count’] = array( ‘articles_count’, false, __( ‘Articles’ ), __( ‘Table ordered … Read more

Default Editor – columns not printing [closed]

The columns appear vertically because when printing, the viewport is considered quite narrow. For the column blocks to appear horizontally next to each other, they have this in the CSS for the core/columns block: @media (min-width:782px) { .wp-block-columns { flex-wrap:nowrap!important } } This media query does not pass when printing, thus the columns appear vertically. … Read more

column values not showing after merging two custom post types

The correct action hook for printing custom column content is manage_loads_posts_custom_column, not manage_invoices_posts_custom_column (tested). This is because the row is itself for a loads post type, and not an invoices post type. Because you’re on the page for invoices, the filter to add columns works with invoices. Tested: add_action( ‘manage_loads_posts_custom_column’, ‘invoice_custom_column’, 10, 2 ); I … 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