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?
- How do I set the default admin sort order for a custom post type to a custom column?
- Make custom column sortable
- Using meta_query, how can i filter by a custom field and order by another one?
- Set post date before 1970
- group search results by post type?
- register_post_type sort order by title by default
- How to order posts of a custom post type by date DESC in dashboard Admin?
- How To Remove These Stuffs From Custom Post Type List Screen?
- Drag n Drop Post Order for multiple Custom Post Types
- Why does my custom taxonomy show a total count across all post types
- Custom sortable columns ordered by meta-value?
- WP_Query() show posts that end later than today
- Add content in custom post type page after the title and before columns
- How to order adjacent posts (prev / next) by custom field value?
- WordPress post sorting with AJAX
- Ordering posts by custom taxonomy in admin area
- Custom Post Type, WP_Query and ‘orderby’
- How to Remove Certain Screen Options and Table Columns from post type in wp_list_table?
- Filter admin columns by custom post field value
- Sorting a query by custom field date
- Custom Taxonomy Template Post List with Sort Order
- Ordering Posts List By Taxonomy Terms?
- Column sorting with emtpy meta values
- Number of pages – multiple (custom) post types
- Add content before/after admin post wp-list-table
- WP_List_Table Inside Metabox Not Working on Submit
- Redirect after deleting post and keep track of pagination
- Uploading DB to server from local is not matching the post dates
- Add custom column at custom posts list
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- 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
- Permalinks using event date (year & month) instead of publication date
- How to sort CPT by custom meta value (date), and return posts month by month
- Date query for a custom meta field
- Alphabetical sorting of custom post type – one letter per page
- sort events based on event date custom field
- How to Sort Custom Field Admin Column by Date
- How to Sort by Date When Using d-m-Y Format
- Custom Post Types – How to include custom fields
- How i add new link after Edit | Quick Edit | Trash | View in quick edit section
- How to make an archive page displaying posts in a date range
- Row actions not showing? Why?
- Is there a way to list posts of only a certain category
- How can I add a column in the wp_list_table of the admin area?
- Query current and future events, ordered by begin date
- How to use custom post type APIs, but use a different db table
- Sort Posts Best Practice
- Custom Post Type sorted by Title
- How to add new tab to admin list of posts and handle result list
- Sort by two dates. Default entry date and custom field if present
- Displaying custom posts only if custom meta box’s date is not expired
- Get the next event using date_query
- How do I sort a custom post type admin column using two meta keys?
- Custom-post-type-archive: posts sorted/filtered by year?
- 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
- sort order for a custom post-type [closed]
- Sort admin area by custom Event Date field
- Custom post type ‘orderby’ => ‘meta_value’ not working
- How to rank custom post type from score points
- Sorting multiple custom post types without a meta key/value pair by sort order
- 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
- WP_Query order by custom field, then randomly order some of results
- Post count by month of taxonmy term
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Custom post type, organized by categories
- 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
- WordPress posts page for customer filtering and sorting along with category filter
- manage_edit-{post_type}_sortable_columns sorts, but wrong!
- Sort entries by date mixing two post types
- Add custom column to post list table
- Meta Query posts not showing on ending date of custom field
- Order a custom post type admin screen by a second custom post type title
- Use the same date-based permalink structure for all post types
- How to order posts of a custom post type by date DESC in dashboard Admin?
- Order post by date with ACF
- sort post types by amount of views
- Custom post type sorting: alphabetical order
- Sort a custom post with ACF: Date Picker & Display Featured!
- Programatically inserted posts not showing in Posts Table
- Sortable column containing numeric values for Custom Post Type at WordPress Backend