I too was struggling with this (only I was sorting by a text-based meta value). Here’s what seems to have fixed the problem:
$meta_query = array(
'relation' => 'OR',
array(
'key' => 'property_reference',
'value' => false,
'type' => 'BOOLEAN',
),
array(
'key' => 'property_reference',
'compare' => 'NOT EXISTS',
'value' => '', //have to set value due to bug: core.trac.wordpress.org/ticket/23268
),
array(
'key' => 'property_reference',
)
);
$query->set( 'meta_query', $meta_query );
$query->set( 'meta_key', 'property_reference' );
$query->set( 'orderby', 'meta_value' );
…where property_reference
is my custom field.
Related Posts:
- Sort custom post type list table by display name of a user id stored as post meta value
- query_posts with a custom post type, a meta_query and sorting by post date?
- How to sort posts in a custom post type by title in ascending order by default?
- Sort custom post type by most current date picker
- Can the Next/Prev Post links be ordered by menu order or by a meta key?
- Custom Post Type Archives by Year & Month?
- Make custom column sortable
- register_post_type sort order by title by default
- How to order posts of a custom post type by date DESC in dashboard Admin?
- Drag n Drop Post Order for multiple Custom Post Types
- Why does my custom taxonomy show a total count across all post types
- WP_Query() show posts that end later than today
- Add content in custom post type page after the title and before columns
- WordPress post sorting with AJAX
- How to Remove Certain Screen Options and Table Columns from post type in wp_list_table?
- Sorting a query by custom field date
- Custom Taxonomy Template Post List with Sort Order
- Column sorting with emtpy meta values
- Add content before/after admin post wp-list-table
- Redirect after deleting post and keep track of pagination
- Uploading DB to server from local is not matching the post dates
- how to sort post in admin column by recently
- Custom Post Type or Custom Tables
- Custom Post type sort order not working in the admin area
- How to sort a table of custom posts by column containing custom field
- How to sort CPT by custom meta value (date), and return posts month by month
- Date query for a custom meta field
- How to Sort Custom Field Admin Column by Date
- Custom Post Types – How to include custom fields
- How to make an archive page displaying posts in a date range
- Row actions not showing? Why?
- Query current and future events, ordered by begin date
- Sort Posts Best Practice
- Custom Post Type sorted by Title
- How to add new tab to admin list of posts and handle result list
- Get the next event using date_query
- get_queried_object error How to show post count by month in the taxonomy page
- How to make in WordPress admin panel sortable column for the custom field, that count the number of page impressions?
- Custom Post Type Events Archive Grouped By Month
- Custom post type ‘orderby’ => ‘meta_value’ not working
- How to rank custom post type from score points
- Order By Post Type ThenBy Taxonomy
- Combining sorted and random CPT
- Add acf field in title (admin table)
- Sorting custom post type columns with external data and without meta values
- Categories sorting
- Wp_query: sort by PHP variable
- WP_Query most viewed posts, in multiple Post Types, last 30 days, excluding a specific taxonomy term
- Crafting WP_Query array, sort by date
- Post count by month of taxonmy term
- WooCommerce sort products by the actual product width(not the shipping width)
- Show post in table front end
- Sort and filter custom post type posts by custom taxonomy
- manage_edit-{post_type}_sortable_columns sorts, but wrong!
- Meta Query posts not showing on ending date of custom field
- How to order posts of a custom post type by date DESC in dashboard Admin?
- Order post by date with ACF
- Custom Post Type page sorts differently on different environments
- I am trying to get cutom post cout by month of current taxonmy term
- How to add query args to links to CPT admin submenu
- Creating a “glossary” of WordPress posts of a specific post type
- Odd behaviour for the update button when displaying a WP_List_Table
- How to display a WordPress Custom Field only on a specific day of the week?
- sort by name (slug) custom post type
- Using WP meta query to show custom post types by a start and finish date
- Sort column on meta key and meta value
- Why does my URL keep returning 404 error code?
- Custom loop request based on custom field
- What’s an easy way of sorting custom post types manually?
- How to order query results based on if a custom field has been populated, then the order by the date of the post?
- How to sort WP_Query by a custom text field (written as a date dd/mm/yyyy)
- Sort custom posts by date and then by taxonomy
- How to set post date in post_type so that it’s same as latest post in category
- Custom post type sortable columns when column value is from a custom database value
- Compare ACF Date field to today or yesterday
- Issue removing columns from admin table
- get_queried_object not work in taxonomy page
- Custom post type order by post_title
- How to sort post category using its Description
- Wp Query sort order from custom MetaBox
- sorting in wp query based on custom field value
- How to sort custom post’s category by id from the theme’s function.php?
- Pre_get_posts comparison with custom field doesn’t work
- Display year value before a set of posts
- Get month and day from a Date Picker custom field
- Loop posts in a table ordered by a custom field value
- group posts by month/date ignore years
- How to display custom post type ordered by a custom field date
- Change custom post status to draft before today
- Change column of row action (Quick Edit) links in WP_List_Table
- Show all post types in the same table of posts [duplicate]
- How to save an integer as taxonomy term?
- Generate daily archive whenever any post type is added
- How can I sort posts ascending by post title for a specific post type, but on a category archive template?
- How to randomize published date for WordPress custom post type
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- Order Wp Query by earliest of 3 dates meta query
- Sort CPT by taxonomy AND THEN by custom field
- Custom order of CPT posts by title, in wp-admin area by default
- Sorting by Title for Post Archive Categories for Custom Post Type