Your question is not very detailed. It is hard to work out exactly what you are doing but I am assuming that you are trying to sort posts by a custom meta meta_key
/meta_value
. This the formula for that (annotated but basically lifted from the Codex):
$args = array(
'post_type' => 'your_post_type', // I don't know what this is
'meta_key' => 'your_key', // I don't know what this is
'orderby' => 'meta_value_num', // only for numbers; use "meta_value" for alphanumerical keys
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'your_key',
'value' => array('your_value'), // can be more than one
'compare' => 'IN', // see the Codex for other values
)
)
);
$query = new WP_Query($args);
Reference
Related Posts:
- WP Query – Is this correct?
- ORDER BY custom field value
- Trying to perform complex custom field query with order by set to field value
- Is there a way to do multiple ordering on a multiple meta_query?
- Ordering posts by anniversary using only day and month
- Display custom post types with custom date field value (before today) & order by custom date field
- Sorting posts by multiple values, combined
- meta_value_num sort glitch
- Sorting posts by custom fields in meta_query
- Alter main archive, to show posts with meta as last
- Meta query with multiple custom fields for archives page ordering problem
- filter custom field values $min $max
- Ordering posts by custom field named “date” in backend
- query posts custom field calculation value
- ORDER BY custom field value out of where clause
- Meta_query ‘compare’ => ‘LIKE’ not working?
- Problem with writting correctly a query posts args in WordPress
- Checking if field is set before comparing with meta_query in query_posts?
- Filter Query Post by Custom Fields(by date)
- WP_Query – Order results by meta value
- Custom query with orderby meta_value of custom field
- Using meta query (‘meta_query’) with a search query (‘s’)
- Using meta_query, how can i filter by a custom field and order by another one?
- Query Posts or Get Posts by custom fields, possible?
- Can I query custom meta data through WP_Query
- Add custom fields to search
- SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
- Matching Serialized Arrays with meta_query
- Meta Query with AND & OR?
- Sort posts by custom field numeric value using dropdown
- query_posts and only show results if a custom field is not empty
- Filter archive.php by custom meta
- Order Posts by Closest Numeric Values
- Order posts by custom field and if custom field is empty return remaining posts
- order by meta_value serialized array
- Order by custom field date with ASC order
- WordPress Search Custom Meta Field Only
- Compare meta_query decimals not working right
- Order Custom post type loop by custom field (datepicker)
- Sorting within nested queries / multiple meta keys
- Calling Specific Pages with wp query Part II
- Order by Custom Field date not recognized
- Comments form custom fields order
- If value present, order posts by two consecutive custom fields
- Loop through two different sets of custom fields
- Query on custom field count?
- Slow meta query with multi meta keys
- Using OR in WP_Query negates the “NOT EXISTS” compare
- How to use query_posts() with a date filter on a custom field?
- How can I query on the year part of a complete date in a custom field?
- How can I combine meta_query queries?
- Displaying posts with only upcoming dates according their custom field date value
- Difference between ‘LIKE’ and ‘IN’ in meta queries
- Order by meta_key with two meta_queries
- WP_Query display next custom post from today’s date
- Can ordering post list by meta_value cause performance issue?
- Order by value in serialized custom field
- Which is best in the following scenario : post_meta vs custom table vs parent/child posts
- WP_Meta_Query causing long-running MySQL queries
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- How do I query for a post by custom field?
- Order Posts by meta value AND published date
- meta query not showing any results?
- meta_query for a string inside a meta field containing a comma-separated list
- Order by custom field value not working for acf date field
- how can i use custom field in query post
- using multiple meta_key and meta_value in query_posts
- Complex WP_User_Query call fails on production server
- Query post order by post and desc not working
- How can I sort homepage by a meta value?
- Meta query with timestamp using WP_query
- Orderby custom field meta value ASC and then by date DESC
- Order query by meta_value with multiple custom fields
- How make a custom search on backend in WordPress without plugin?
- How to add a new meta key and assign timestamp to posts
- Show 1 post and after a specific date show the next one
- Get content from pages with same meta_key from Database
- WP 3.1 meta_query for multiple custom field values
- How to select posts from multiple categories and metavalues?
- meta_compare seems to be treating values as strings instead of integers as expected
- Fetch Record based on meta key dates
- Order RSS content by an advanced custom field value
- How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?
- how to make members list directory through wordpress post custom meta key.
- query_posts with sorting on a custom datestamp
- Order a query by meta_value and then by post_date
- query post based on comparison
- Query Posts Via WordPress URL
- Meta_query not filtering posts
- Order by custom field in query multiple
- Transfer taxonomy to custom field
- Filtering posts by WORD in custom field
- Display agents (custom post type) alphabetically, except one who always shows last
- How do delete a meta key?
- Can’t sort custom column on user.php by number / meta_value_num?
- Dynamic background image used in css after selector
- WP Query Args – search by meta_key or title
- get_the_ID() retrieves same ID on Gutenberg’s Query Loop
- SQL query based on two different custom field values
- Sort posts based on an acf field called fecha value return longtext ‘20240517’