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)
- 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?
- SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
- Matching Serialized Arrays with meta_query
- query_posts and only show results if a custom field is not empty
- Order Posts by Closest Numeric Values
- Order posts by custom field and if custom field is empty return remaining posts
- WordPress Search Custom Meta Field Only
- Compare meta_query decimals not working right
- Order Custom post type loop by custom field (datepicker)
- Order by Custom Field date not recognized
- Comments form custom fields order
- 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?
- 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?
- Which is best in the following scenario : post_meta vs custom table vs parent/child posts
- WP_Meta_Query causing long-running MySQL queries
- meta query not showing any results?
- meta_query for a string inside a meta field containing a comma-separated list
- 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
- Orderby custom field meta value ASC and then by date DESC
- 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)?
- Trying to sort and display categories(not posts) by custom field: ‘order’
- Use meta_query to get title of associated post
- get posts where a custom field contains a text
- Query_posts with custom field meta value
- Avoiding ACF get_field and returning to core WordPress function
- Unable to get specific value from post meta
- comment meta_query for keys that aren’t yet set
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- change order of images attached to post
- Sortable Custom Columns not sorting correct
- Diamond question mark in text after migrating content
- Custom search SQL Query to add custom field in result
- tax query between operator like
- How can I change the publish date based on a custom field?
- Order custom fields alphabetically
- Ordering by ‘Title’ OR ‘Custom Field’
- Best way to sort estates and query them (for rent? yes/no. contains office space? yes/no)?
- Is it possible to compare the current time with a custom “start” and “end date
- Get author total post votes from post meta
- How can I modify my meta_query to work with prices that are stored in the database that contain dollar signs and commas?
- simple fields plugin custom query
- Need to search a custom field (ingredients, one long string per post), but want it to allow phrases/non-exact matches
- Making WP_Query limit results by date before today where date is a meta_query
- multiple meta_query and orderby question
- How to improve my non-unique metadata MySQL entries?
- Orderby if between two meta fields
- Ordering by ACF custom field vaule
- Sort by an ACF field in a tax_query
- Filtering posts by ACF meta query
- Why does my numeric meta query work only on one meta key and not the other?
- meta_query to check all custom fields
- Query multiple meta values at the same time :
- Create Shortcode shows only posts with custom_field meta
- query_posts -> get page_id from custom field
- query_posts with sorting on a custom datestamp
- Query Posts Via WordPress URL
- Meta_query not filtering posts
- Order by custom field in query multiple
- 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?
- Dynamic background image used in css after selector