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
- Including Custom Meta with posts_where query
- how do i remove posts from a WP_Query so the pagination is right?
- Very Slow Page – How to Optimize # of Queries?
- Can I create a loop with multiple post types and specify different $args for each post type?
- Combining sorted and random CPT
- Display CPT posts based on specific taxonomy
- WP_Query: include custom post type only with specific meta value
- WordPress custom loop filter by meta_key and value with serialize data
- Returning a list of custom post types excluding those without a specific meta_value
- How to make sure content doesn’t display if selection is empty
- Show one item per category of a custom post type
- Meta Key Value in current-user-only loop
- Calculate all custom field values in the post loop
- Rewrite and custom post type: order by custom field not working
- wp_query check if integer exists in custom field’s array
- Previous/Next Link by Meta Value in CPT
- Wp_query: sort by PHP variable
- Custom loop with multiple taxonomy queries
- What is the recommended / best way to do this: Event calendar post/type in a block-based theme?
- How can I get the number of custom post type posts that have a specific attachment image set?
- Problem querying Custom post type by custom fields
- Orderby CPT custom fields not working
- WP_Query order by custom field, then randomly order some of results
- Query custom post type with ACF Date
- How to do WP_Query with two meta fields with orderby clause
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Including metaboxes from custom post types in global search — continued
- Query Multiple Custom Posts by Custom Fields
- What’s the WP way to load remaining custom posts?
- Order by empty custom field
- Get Posts by multiple custom fields is not working
- WP Query with categories only shows one post and ignores the category
- Problem: wp_query outputs all images on site
- First custom field value (out of several) displayed twice after query
- Change sort order when using ‘orderby’ => ‘type’
- Possible to filter custom post type with multiple meta data?
- pagination not working for category.php (custom post types in categories)
- Query based on custom fields start and end date
- Wrapping x posts in html without leaving empty html
- WP Query post__in not returning correct results
- Sort posts in loop by the WooCommerce Membership of the author
- DIsplaying URL of custom field in last post of certain taxonomy && post type
- 4 column-loop ordered alphabetically with entries grouped (and labeled) by their first letter
- Add a custom meta box for client to order CPT posts how they want
- How can I group posts by months and years?
- Multiple Custom Post Type queries, how to DRY it up
- Custon Content within WordPress Loop
- Loop increase number
- WP Query ‘posts_per_page’
- Using wp_query to modify the loop in index.php for a CPT
- Display post from a date range from custom field
- Custom WP_Query doesn’t display all posts
- Query & the_content() is showing in the header
- post_per_page ignored in WP_Query
- How to get specific post meta by title or id
- get_pagination not working on a custom post type query (using WP_Query)
- WP_Query with custom post type ID
- Getting a custom post’s custom field based on another custom post’s custom field select
- How to conditionally add Custom Post Type to Front Page
- hide specific div on single.php [closed]
- WP_Query orderby not work with meta_key
- Pagination not working on custom query on a page
- WP_Query of custom post type sorted by meta_key has unexpected results
- How do you output an unknown number of images in a custom post type with desired markup?
- Get data from PHP to JavaScript to set position of each post on front page
- WP_Query not resetting after wp_reset_postdata
- display posts of custom post type with custom taxonomy
- Display custom post type for specific user
- Get post content from another section in custom single page
- Custom Post type loop with ACF not displaying properly
- Trying to add a class to post links
- postsperpage value not being applied
- Group by custom field value (start and end times)
- Display the current post in browser as the first post in a loop (for a slideshow)
- Post ordering not working with custom field
- Display post from custom post type
- List all Custom Post Type posts excluding certain Taxnomy term
- Filtered by a custom field, ordered by another
- foreach loop inside the loop creating duplicates in output
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- Displaying information from custom field on custom post type
- How to fetch posts that are stored in the different table than (default) wp_posts?
- Cant’ Display Custom Post Type Title Base on Tax Terms