I had trouble with a similar issue of sorting posts from a custom post type in a specified order on their archive page. I used http://wordpress.org/extend/plugins/sort-query-posts/.
The plugin lets you sort posts by author, comment_count, date, id, menu_order, modified, parent, or title. It only requires you to add the following lines
<?php query_posts(array('post_type'=>'post_type_name', 'posts_per_page' => 20)); ?>
<?php sort_query_posts_by('sort_type', 'order'); ?>
to your code, before the loop. Where ‘sort_type’ is the item by which your posts are sorted and ‘order’ is asc, desc, or rand. (very clear instructions in the short readme file).
Related Posts:
- Query all posts where a meta key does not exist
- Meta query with boolean true/false value
- Get post with multiple meta keys and value
- How Do I Use WP_Query to Run This Database Query as Search Result?
- Can’t sort order of wp_query with 2 meta keys
- Query for posts from any post type but only add instock products
- WordPress Orderby Numeric Value Not Working
- Display custom post type from dynamic custom field
- WordPress request fiter order by related post’s post_title
- Displaying a div from an assigned meta_value when on a page
- How to get specific post meta by title or id
- $post->post_meta not pulling any post in wordpress/php
- WP_Query of custom post type sorted by meta_key has unexpected results
- Returning a custom content types with meta values
- WP_Meta_Query object with conditionals
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- After inserting new post with wp_insert_post() the post is not visble to WP_Query, but the same WP_Query works for post inserted from wp-admin panel
- Use WP_query to match post types based on custom field values
- How to sort by multiple values in a nested WP_Query
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- How to get post by meta value
- How do I get all authors posts of a custom post type outside loop
- Linking posts together with Advanced Custom Fields “both ways”
- How to get Current week and current date record wp query
- How to get post meta for custom post type and taxonomy
- get_post_meta for Custom Post Type ( CPT )
- WordPress custom post type
- Custom Post Type meta oembed html output resulting in WSoD
- Values inside a custom field to determine which category posts to display
- Querying meta values within an array
- Quering a post object based on another related post object
- Wp_query: sort by PHP variable
- WP_Query most viewed posts, in multiple Post Types, last 30 days, excluding a specific taxonomy term
- Custom-Posttype & Custom Taxonomy WP_Query
- Crafting WP_Query array, sort by date
- Custom loop with multiple taxonomy queries
- Return one unique custom post type result when it shares a custom taxonomy in WP_QUERY?
- How to implement a Google map store locator
- Converting the_content string to an array?
- forming WP_Query for posts of all post types but from specific categories
- Get latest 3 posts from multiple CPT in one query
- Deleting Custom Posts & Meta Data on Uninstall
- Loop to fetch 3 post_thumbnail instances from 3 most recent custom post types named “portfolio”
- Widget: Custom Post Type Post Listing Dropdown on Admin Side
- Display upcoming Events for next 7 Days
- Post image in WordPress not appearing on home page
- How do I create an archive page as a including metadata?
- Isotope Filtering with Bootstrap Tabs – Custom Post Type Query Loop in each Tab (Have to click twice to filter)
- Custom post ui plugin & WP_Query – Polylang
- changing meta value and meta key of price field
- How can I get the number of custom post type posts that have a specific attachment image set?
- Posting to a Custom Post Type from front end – user generated content
- How to use load more custom post type data normal or according to on click category tab In WP
- orderby rand is not working for a custom post types
- Update Post Meta for a logged in user
- Getting meta in editor plugin, and event triggering issue
- Problem querying Custom post type by custom fields
- Orderby CPT custom fields not working
- Custom taxonomy rewrite give pagination 404
- How to duplicate entire custom post type
- WP_Query order by custom field, then randomly order some of results
- A better way to add a meta box to custom post types
- Restrict Access to Posts based on Custom User and Post Meta Data
- WP_Query inside foreach loop returning same value for all options when filtered using ajax
- Mixing 2 custom post types with posts output in specific pattern
- Custom post taxonomies as tax_query terms?
- Two Custom Post Types Many to Many Relationship
- get_post_meta not working on publishing
- Should wp_postmeta meta_key always be unique for a given post_id?
- creat filter with wp_query
- Troubles with acf/save_post and WP_Query
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- Query custom post type with ACF Date
- How to do WP_Query with two meta fields with orderby clause
- Stuck in Order by more then one
- Display featured image from one CPT within another CPT query
- how can I register a post_meta field in an existing CPT and then call it again with get_post_custom()?
- get_post_meta returning no value in custom post type alert email
- Custom WP Query on custom meta and sort by multiple meta keys value
- Show only one post on custom post type archive
- Woocommerce search pagination not working
- How to order WP_Query by parent for hierarchical Custom Post Type?
- Including metaboxes from custom post types in global search — continued
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- post meta parameter in post custom-post-type endpoint with restapi
- How can I made custom taxonomies relationship?
- How do I set all of a particular post meta to a value within the custom post type I’m in?
- Query Multiple Custom Posts by Custom Fields
- What’s the WP way to load remaining custom posts?
- Why is this query not working? (Standard posts + custom post type)
- How do you paginate a query grouped by month?
- Custom taxonomies relationship
- Get Posts by multiple custom fields is not working
- Custom post type ‘articles’ ignores posts_per_page, reserved post_type?
- Several post types on WP Query by tag and taxonomy
- Update postmeta Parent when post_status child change
- WP Query with categories only shows one post and ignores the category
- Metabox not show in categories custom post type cmb2
- Polylang non-default language ignores tags in WP_Query
- Custom Widget WP_Query problem