Your query args are not quite correct. When you want to order by a custom field, you need to specify a meta_key
argument, and set your orderby
to the kind of ordering you need. For example:
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'topic',
'field' => 'slug',
'terms' => 'movie',
),
),
'post_type' => 'essay',
'meta_key' => 'topic_number',
'orderby' => 'meta_value_num',
'order' => 'DESC',
);
Related Posts:
- WP_Query on custom post type not displaying, multiple loops & get_template_part
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- WP_Query post at custom position
- wp_query to find posts by year and month
- WP_Query orderby modified to include custom meta changes
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- Order Custom Post Type by Custom Field Value
- How do I list a custom field and custom taxonomies for each result in a loop?
- Order posts alphabetically with numbers but some of the posts has numbers in the title
- SEARCH QUERIES – REVERSE OUTPUT
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- sorting in wp query based on custom field value
- WordPress query in which condition uses custom field
- WordPress loop add heading before first of type
- How to make a shortcode for my WP_Query Loop? [duplicate]
- Error in WP Query. If variable is empty it is displaying previous post value
- 404 on Pages for Custom Post Type & Query_Posts
- WP_Query orderby custom field then post_date in one query
- Select All in Parent Category, Group by Child Category?
- Filtering a WP_Query meta_query by numeric values isn’t working
- WP_Query to loop a Custom Field, Custom Post Types do not show
- How to show posts from multiple post types in a single loop? And display them separately on the same template
- Get post info inside modal window?
- WooCommerce – Show orders for a specific product ? [closed]
- Get_post_meta() won’t return value
- Query Custom Post by Category
- Having trouble with custom date field for CPT query (WordPress)
- Display posts if a custom field value is equal to another custom field value
- WP_Query and using a variable for ‘cat’=> in the args array = WP Bug?
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Display custom post on home page based on a metabox selection
- Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
- Lists Posts from CPT that match the Title of the Page
- Filtering by Post Meta Custom Fields – Performance
- WP Query—Relationship between two custom post types and their fields
- Remove duplicated values from a loop
- How to insert content from another Custom Post type into Post?
- Returning a list of custom post types excluding those without a specific meta_value
- Calculate all custom field values in the post loop
- Custom loop with multiple taxonomy queries
- WP_Query order by custom field, then randomly order some of results
- How to do WP_Query with two meta fields with orderby clause
- What’s the WP way to load remaining custom posts?
- Get Posts by multiple custom fields is not working
- Problem: wp_query outputs all images on site
- How can I group posts by months and years?
- Multiple Custom Post Type queries, how to DRY it up
- Display post from a date range from custom field
- post_per_page ignored in WP_Query
- Getting a custom post’s custom field based on another custom post’s custom field select
- Pagination not working on custom query on a page
- Display custom post type for specific user
- Trying to add a class to post links
- Post ordering not working with custom field
- List all Custom Post Type posts excluding certain Taxnomy term
- Custom PT, Taxonomys and wordpress query
- How can i loop through custom post type according to custom meta field?
- Changing WordPress sort order for returned child pages
- Multiple custom post type queries causing wrong post types to be grabbed in taxonomy + single templates?
- Custom post type pagination error
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- WP query_posts group by meta field related
- Page that lists publications by classifying them by taxonomy
- posts_per_page in custom WP_Query does not override “Reading” settings?
- WP Query from two Custom Post type fields as statement
- Exclude a specific post in a Custom Post Type
- Display Parent-Child Posts in specific order by comparing IDs in array
- WP Admin Dropdown List Filter for custom (ACF) field on custom post type(s)
- Filtering posts based on three taxonomies
- when looping through custom post data not appearing
- Error in the page of a CPT file in WordPress
- Sort custom post archives by a meta value from a different custom post type?
- post_type incorrect for custom post type
- Staggering featured post using ‘sticky’
- Custom post types – meta_query: search lesson which starts sooner
- Adding a Section for Visitors
- Custom taxonomy template for custom fields loop [closed]
- Sort loop by custom field from different post type
- What’s the most efficient way to get two queries based on an if statement?
- WordPress loop, show only one post per custom field
- WP Query with multiple post types ordered by custom meta date then published date
- How To Loop Through list with Custom Post Types
- Custom post order when using OR relation
- Custom Post Type + Category archive
- How to get past and upcoming post by defining date in custom field?
- Post data in separate divs with incrementing class using WP_Query
- Selecting posts older than the current Unix epoch timestamp
- WP_Query get posts where post_name is empty
- Get result from Custom Field in Custom Post type
- Query recent posts by author
- Custom post-type’s pagination not working in category.php
- Querying meta values within an array
- Filter Custom post type by another Custom post type
- WP_query orderby not working after WP4.0 update [closed]
- How do I correctly query posts from a post ID?
- display custom post type from register taxonomy
- Custom post type and have_posts() return empty result
- Query order by meta value force specific tag first
- Order Wp Query by earliest of 3 dates meta query
- WP Query + custom fields: How to query event posts from the current date backwards 6 months and organize it month by month?