to sort the posts by a meta field you need to have this field in meta_query and in orderby like this
$query_args = array(
'post_type' => 'MY_POSTTYPE_NAME',
'post_per_page' => -1,
'meta_query' => array(
'show_post_query' => array(
'key' => 'SHOW_POST',
'value' => '1'
),
'MY_FIELD_NAME__order_by' => array(
'key' => 'MY_FIELD_NAME',
'type' => 'NUMERIC',
'compare' => 'NUMERIC',
)
),
'orderby' => array( 'MY_FIELD_NAME__order_by' => 'ASC' ),
);
$query = new WP_Query( $query_args );
Note the MY_FIELD_NAME__order_by does not have “value” set so it will not be used for searching but will be (let’s say) named so you can use it as column name when sorting.
Related Posts:
- Display all posts in a custom post type, grouped by a custom taxonomy
- Exclude a category from WP_Query
- $wp_query->queried_object->ID throws warning: Undefined property
- Select All in Parent Category, Group by Child Category?
- get_query_var() not working in pre_get_posts
- query multiple taxonomies
- Custom Taxonomy with Custom Post Type Finds No Posts
- The Operator “NOT IN” Does Not Work In tax_query
- Counting Posts of a Given Post Type Having a Specific Taxonomy?
- Custom query – alternate posts by category
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- How to get_queried_object on multiple objects?
- how to group custom post type posts by custom taxonomy terms
- Displaying Posts Related to Other Posts by a Taxonomy Term?
- Sorting a list of posts displayed under a list of associated terms (which should be sorted without initial articles)
- How to get the parent’s taxonomy?
- Querying Posts by Taxonomy From Alternate Network Site
- Sort the main query in subcategories/terms?
- Help with hierarchical custom taxonomies and permalinks…almost there
- Custom Taxonomy List links being re-written
- custom post type paging not working past page 3
- Should unaltered default loop/query return a list of custom posts belonging to a custom taxonomy?
- Want to filter only parent post in admin area
- Multiple Archive Pages for Custom Post Types AND Taxonomies
- Custom Taxonomy and tax_query Issue?
- Query for posts in 2 taxonomies
- Exclude current post when getting related post on custom post type and taxonomy
- Display Posts of a Category in Alphabetical Order (Custom Post Type)
- Ordering Custom Post Types with WP_Query
- Multiple custom post type queries causing wrong post types to be grabbed in taxonomy + single templates?
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- Related “custom post type” using “custom taxonomy”
- What is the most efficient way to execute recursive complex queries?
- Sorting the Loop by Taxonomy Value
- custom taxonomy pagination 404 error
- Ordering by meta value not working
- set object terms after some some time of published post – functions.php
- Sort custom posts by date and then by taxonomy
- have to do a while have post to show for two custom post types sharing the same taxonomy?
- custom post type and a “sticky” position taxonomy
- Display post count for a specific month
- display post count in archive page that have relation with another taxonomy term
- How to search through all child taxonomies using WP_Query?
- WP_Query to display number of custom post type filtered (order by) taxonomy
- WP_Query for custom taxonomies showing posts from non-specified terms?
- Live search by custom tag
- Query a custom taxonomy in a function to create an csv file
- WP_Query based on ‘s’ and tax_queries
- WP_query sort by taxonomy
- Custom Taxonomy – fields
- CPT Loop, include taxonomies and disclude others?
- Ajax load more inside custom post type taxonomy
- WP Query tax_query not returning posts
- Create a custom wp_query from a specific custom post type with specific taxonomy
- The most recent post of custom taxonomy
- Why get_posts() returns empty array while I am trying to get posts from some specific taxonomies and work properly with others?
- Problems with the WP_Query query for a Custom post type
- Displaying WordPress posts from post and custom post type in custom taxonomy
- Display all Custom taxonomy terms and their relevant custom posts
- Get posts of an specific term of a custom taxonomy
- Query pulling all taxonomies, not one I am specifying
- Checking Taxonomy Terms for a Custom Post Type With get_the_terms Not Working
- CPT Efficient way to display posts from different categories with custom query
- Get archive of posts separated by taxonomies and subtaxonomies
- Query Pulling the same post twice
- Custom post type and custom taxonomies display
- WP_Query for CPT with filter by another WP_Query
- Get posts associated with custom taxonomy alternate way
- How to pass taxonomy terms to WP_Query along with $args?
- WordPress custom post type
- Loop with Custom Post Type and Taxonomies
- Custom Taxonomy Query by Taxonomny not working
- How to query posts by meta keys AND under specific category?
- Shortcode display CPT Query only showing 1 post?
- tax_query showing no results
- Post data in separate divs with incrementing class using WP_Query
- Values inside a custom field to determine which category posts to display
- How to display elements of different post types?
- Storing/querying custom date data
- WP Query Post Type with same Taxonomy name
- WP Query WordPress Post Type with the same Taxonomy name
- How to list groupings and keep pagination
- How to retrieve taxonomy terms of the current custom post?
- Listing all custom post types using a specific term on the said term’s template page, in groups
- Catergory args causing loop not to show
- How to Get The Taxonomy Term in Custom Post Type Loop Inside a Wp Query
- display custom post type from register taxonomy
- Attaching multiple custom taxonomies to one CPT?
- Get X posts with the same terms as the current post (custom post type and custom taxonomy)
- WP Query Conditionally query meta and taxonomy
- Sort ACF by custom taxonomy
- Complex Custom Loop with Includes
- Query custom post type and group by taxonomy
- WP Query – Can’t get posts with specific taxonomy
- Dynamically count the number of custom post types associated to a custom taxonomy
- WP_Query not using relation key as expected and not producing any results
- WP Query filtering by custom category not showing all relevant posts
- How to assign a single-menu-template to a menu-items in a taxony/ cat/ subcat/ subcat-item
- Custom fields disappearing when a custom post type is assigned
- wp_insert_term how to insert “” in description