You have to use "orderby" => "meta_value_num"
and set a "meta_query"
at the same time. Then choose the "meta_key"
you want to order by.
Try:
$query = new WP_Query(
array(
'post_type' => 'some_cpt',
'posts_per_page' => - 1,
'meta_query' => array(
array(
'key' => 'active',
'value' => '1',
'compare' => '=',
)
),
'meta_key' => 'ranking',
'orderby' => 'meta_value_num',
'order' => 'ASC',
)
);
Related Posts:
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- Sorting: custom query with orderby meta_value_num THEN by title
- How to get order of posts?
- Revolution Slider Orderby Two Custom Fields
- Meta query with order by another custom field
- How do I sort posts with multiple pages
- Sort wordpress custom posts based on meta value
- WP_Query: Group events by year, sorted DESC; then by date for each year group, sorted ASC
- Understanding the orderby in WP_Query?
- Help ordering Post loop by two meta values
- orderby ignored by wp_query
- How to sort store location by specific category order in WP store locations
- How to sort wordpress posts already selected by WP_QUERY
- Order by value of Custom Field using url string
- Order 2 meta_queries differently in WP_Query?
- Display three sequential posts on each page load, without repeating previous
- Wrap group of wp query posts to parent div by date/year
- Sorting: custom query with orderby meta_value_num THEN by title
- query_posts with sorting on a custom datestamp
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- WP_Query orderby date not working
- Order by optional meta key?
- Order by DESC, ASC in custom WP_Query
- WP_Query order by multiple meta keys & fields
- Display List Of Posts Containing a Relationship Field Value [ACF]
- Using OR conditions in meta_query for query_posts argument
- Secondary Sort (fallback) for WP_Query
- Query Posts in a Predefined Order
- Sort posts by category name and title
- Order posts by ID in the given order
- ACF Relationship Field Search Filtering [closed]
- Custom WP_Query order by post_meta and (author) user_meta
- Sorting posts by custom date fields (non standard date format)
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- WP Query orderby meta key natural sort?
- How to order posts tag by tag?
- How do I order pages and categories by ID or name in the same query?
- Loop through all tags & output posts in alphabetical list
- ACF datepicker meta_query Compare Dates in m/d/Y g:i a – Not in Ymd Format
- WP_Query ordered by custom field that is a date string?
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- WP_Query sort by comment meta data
- WordPress meta_query and order by custom field
- Order posts by tags count?
- Merge 2 args in one WP_Query and order it by date
- Orderby = none not working [duplicate]
- WP_query ‘orderby=none’ Problem
- Sorting Posts by custom field
- Order posts by date and then by custom field
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- Sorting meta_value as integer doesn’t work
- Order posts ascending with number in title
- List taxonomy terms plus their latest post ordered by post date
- Order by the results of a function with WP_query
- meta_query with array as value
- Sort in WP_Query(), not filter? Is it possible?
- query posts in functions.php and update a field
- How to order posts in wp_query by a meta_value of the corresponding author
- Front End Sorting Questions
- Woocommerce custom loop to show all the products [closed]
- Sort by meta key on archive page
- Order by menu structure
- How to sort posts in admin by titles with dd.mm.yyyy format?
- WP_Query order by date in meta_value
- Query Set Order By Author
- WordPress: Keep order of query_posts list of post ID’s using post__in
- How to use order RAND() on WordPress?
- Show all parents and children in custom post type in right order
- Ordering by meta_value AND date NOT WORKING with wp_query
- WP_Query orderby breaks when using AJAX?
- Order WP Query posts by custom order calculated from post meta values
- How to make orderby ‘meta_value_num’ OPTIONAL?
- Custom Post order for homepage
- Minimising number of queries on a page when using Advanced Custom Fields
- Change default ordering of taxonomy terms – pre_get_terms
- Query Posts depends on custom field inside repeater field using acf
- WordPress WP_Query orderby being overwritten
- WP_Query Order by Specific Post ID First
- Order Posts by meta value AND published date
- ACF Relationship + WP Template Parts
- How can I pick a single post from the latest 3?
- Wp query orderby ‘title’ doesn’t work
- Minimising Database Queries when using Advanced Custom Fields
- How can I order Wp_Query hierarchically?
- ACF – Get lowest & highest value from field
- How to orderby meta_value_num with dollar ($) sign
- Sorting posts DESC based on the number of comments using WP_Query
- If two first numbers exist in wp_meta_query value
- WP_Query ordering numbers as letters
- WP_Query meta_query >= date
- Order WP_Query by multiple fields, subtracting them from one another
- Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?
- pre_get_posts order by not working
- WP_Query posts by distance based on LAT & LNG in Database
- How To Fix WP Query Returns Results But Shouldn’t?
- Combining sorted and random CPT
- ACF Date Based wp_query
- Multiple taxonomy And acf filter group by
- Changing WP_Query params with url Query Var
- (Solved) WP_Query ($ args) -> How to sort letters and numbers within the same array