Is there an easy way to do this without having to unserialize it?
Not in any reliable way. You can certainly ORDER BY
that value but the sorting will use the whole serialized string, which will give you technically accurate results but not the results you want. You can’t extract part of the string for sorting within the query itself. Even if you wrote raw SQL, which would give you access to database functions like SUBSTRING
, I can’t think of a dependable way to do it. You’d need a MySQL function that would unserialize the value– you’d have to write it yourself.
Basically, if you need to sort on a meta_value
you can’t store it serialized. Sorry.
If you can’t change how the value is stored you will need to pull your posts, loop through them to sort them, then loop through them again to display the sorted results.
Related Posts:
- Using meta_query, how can i filter by a custom field and order by another one?
- Display custom post types with custom date field value (before today) & order by custom date field
- what is the correct way to compare dates in a WP query_posts meta_query
- Return all custom meta data for one custom post type
- meta_query for keys that aren’t yet set
- Fail to compare dates in meta_query
- How to filter custom posts by tags and custom fields?
- WP_Query orderby custom field then post_date in one query
- Filtering a WP_Query meta_query by numeric values isn’t working
- Querying custom post type with 2 custom fields (date-range)
- Display Custom Post Type Fields
- How Can I save multiple records in same meta key?
- How to hook get_terms() to only show count of posts that have custom meta
- Using Query Posts With Multiple Post Types And A Taxonomy
- Comparing timestamps in meta query doesn’t work
- Display two post types ordered by two custom fields
- Used with meta_query in query_posts works slowly
- How loop through posts based on custom fields
- Filtering by Post Meta Custom Fields – Performance
- How to insert content from another Custom Post type into Post?
- meta_query compare >= not working but
- WP_Query: include custom post type only with specific meta value
- Returning a list of custom post types excluding those without a specific meta_value
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- wp_query check if integer exists in custom field’s array
- Filtering custom post type on a combination of custom taxonomies and custom fields?
- Get posts between custom dates
- Meta Query Not Returning Output Despite Having Matching Values
- Meta Query Filtering not working on Custom Meta Box using Radio Buttons
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Meta Query posts not showing on ending date of custom field
- Admin Custom Meta Box – Pull Last 5 Posts from Custom Post Type
- How to Output which matched meta_keys were found from custom_type_posts?
- Possible to filter custom post type with multiple meta data?
- filter search custom field query
- How to let users choose where to search for posts?
- Query based on custom fields start and end date
- Getting a custom post’s custom field based on another custom post’s custom field select
- Querying multiple values from a single key
- find custom post type post by searching its custom field with my string
- Custom Query: If One Post Object Field Value Is The Same As Another
- Best way to create a search for custom post type by custom field values
- Incorrect ordering of custom post type based on time
- Display Posts Query with IF function
- WP query_posts group by meta field related
- order the meta query results by 2 custom fields
- Using OR relation in meta_query to check for a value before sorting by another
- Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
- Meta query and compare “!=” not working as expected
- Orderby if between two meta fields
- Use WP_query to match post types based on custom field values
- Show posts from WP Custom Post Type selected from a field in a metabox
- meta query multiple values for the same key
- Sort custom post archives by a meta value from a different custom post type?
- Custom post types – meta_query: search lesson which starts sooner
- Meta_Query refuses to return results
- Sort loop by custom field from different post type
- Meta_query by date for Events archive
- Query events post type after current date and timezone
- Selecting posts older than the current Unix epoch timestamp
- Unable to get the upcoming events for custom post
- Filter RSS feed for custom post type to events for next 7 days only
- Query Distinct Taxonomies of Custom Post Type
- Custom Query With Multiple Meta Key Value
- WP_Query arguments: Loop through custom post type – get all entries except excluded meta_key?
- loop through custom post-type with two meta_keys
- Querying meta values within an array
- How to grab data (titles, thumbnails and custom fields) from multiple posts to populate a new array efficiently?
- Custom Post Type + Custom Meta Query Not Showing 2012 Posts
- Get Posts ordered by a date custom meta field
- Check for custom field value in different post type than current one and do something
- Function to Compare CPT Post Custom Value with Default Posts CF Value
- Display ACF object field data using Elementor Custom Query
- Custom Taxonomy Template Post List with Sort Order
- Ordering posts having multiple post-meta date fields
- Add custom column to custom post type overview in backend
- Loading post content in FancyBox
- Using a Custom Field instead of original title field but only for Custom Post Type
- How to initialize PODS?
- WordPress posts with multiple fields
- List of Posts in a Custom Field
- CPT Group by Date metabox Value
- Query Custom posts of same taxonomy as the post itself
- Trash / Draft a WordPress custom post after custom date field expires
- Posting to a Custom Post Type from front end – user generated content
- Custom Meta Field – Remove comma from string with str_replace
- Category with post type pagination returns 404
- Filter custom post types by a field value
- Is it possible to activate customfield ‘text description’ upon activating the customfield ‘checkbox’?
- Custom Field values not Showing in Edit Page of Custom Post Type
- How to make WP_Query not to show irrelevant posts?
- How to call a post’s metadata in shortcode.php?
- Ideas to connect external database table to wordpress posts as custom field source
- How to sort WP_Query by a custom text field (written as a date dd/mm/yyyy)
- Query custom post type and custom field by URL parameters
- Create Inclusions and exclusions
- Querying, storing, and using data from 2 separate custom post types
- Custom Info Box at end of posts?
- WordPress custom post type queries