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
- Order by optional meta key?
- WP_Query order by multiple meta keys & fields
- 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?
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- Merge 2 args in one WP_Query and order it by date
- query posts in functions.php and update a field
- Woocommerce custom loop to show all the products [closed]
- Minimising number of queries on a page when using Advanced Custom Fields
- WP_Query Order by Specific Post ID First
- ACF Relationship + WP Template Parts
- Minimising Database Queries when using Advanced Custom Fields
- If two first numbers exist in wp_meta_query value
- WP_Query meta_query >= date
- Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?
- How To Fix WP Query Returns Results But Shouldn’t?
- Combining sorted and random CPT
- Include custom field in Ajax search WordPress
- Orderby ASC changes to DESC in WP_Query
- Order Custom Post Type by Custom Field Value
- Excluding pages in WP_query using ACF
- Advanced ordering of query_posts
- How to do a wp_query with two acf-fields, sorting on one of them
- Using Advanced Custom Field for file upload, how do I load the file url
- Stuck in the query loop
- WP_Query with meta_query dosen’t return results
- Does wp track views for posts?
- how to get post order by post id wp_query?
- Include post content of linked posts in search
- How to Create a Random List of Child Pages
- Specify strict ‘order by’ in WordPress query
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Merge 2 custom post type posts and taxonomy terms and sort ascending
- Order BY Most Liked And Published Between Previous Week Monday And Next Week Monday
- Display all posts in a custom post type, grouped by a custom taxonomy. How to sort the posts alphabetically and the terms by ID?
- WP Query and date format
- How order posts from category by date and comment count?
- Get a list of ACF Repeater-Fields as array
- WP_User_Query orderby meta_val_num
- WP_Query custom order and pagination
- Sort posts using multiple custom fields and menu_order in single query?
- Order WP_Query by meta_key priority when ‘OR’ relation used for multiple meta values
- Multi-layered WP_Query
- Oxygen Repeater Advanced Query
- WP_Query order by multiple meta keys & fields
- WP_Query for distinct meta values
- Group Product Types
- Sort custom posts by date and then by taxonomy
- Order (by ASC) posts with meta_key so posts without values are last
- WPQuery Date and ACF
- Populate select list with meta values from all posts of a Custom Post Type
- Form checkbox value going to dynamic URL
- how to include orderby value that is empty?
- Custom Woocommerce Product Query
- WP Query by variable custom field
- Move some posts to end of sort order, even if there is a sort in the wp_Query already
- WP_User_Query Orderby Not Working
- How to get taxonomy image attached to a Post Type WordPress
- Order posts by tags count?
- Query Order By Number Variable From API
- How to query wordpress with array of meta_values?
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- Limit default Search query to post_title
- Order & Orderby clause not working with custom query
- How can I modify standard search query to include also ACF custom fields values?
- Pin to Top Functionality using orderby custom field then event date
- Best way to Order Post in Home without a plugin
- Query All Attachments and Order by Parent Publish Date
- Sorting posts by meta values: 2 different orders
- Order posts by custom column using pre_get_posts
- Geo location query inside wp_query?
- Add filter to Orderby Parameter using Array
- Order WP_Query results in order other than ASC or DESC
- Custom query to order by multiple taxonomies
- Get post closest to today
- orderby in WP_query doesn’t works
- Order by meta values
- orderby and order filter in get_posts or WP_query function in wordpress not working
- Get posts using multiple values from ACF checkbox as meta query wordpress
- Best performance for use Custom Field in WP
- new WP_Query with order args – no more distinction between categories