Found an answer to this.
Somehow WordPress’ own orderby
isn’t fully functional when trying to order by multiple values.
I solved this by changing WP_Query
to SQL Query
, and including second DESC
after _postmeta.meta_value+0
SELECT XXX_posts.* FROM XXX_posts
INNER JOIN XXX_postmeta ON (XXX_posts.ID = XXX_postmeta.post_id)
WHERE 1=1 AND XXX_posts.post_type="sidebar_element" AND (XXX_posts.post_status="publish") AND (XXX_postmeta.meta_key = 'sidebar_element_meta_alignment' )
GROUP BY XXX_posts.ID
ORDER BY XXX_postmeta.meta_value+0 DESC,XXX_posts.menu_order DESC
Related Posts:
- How can I sort posts by the date and a custom meta field?
- WP_Query sort by meta_value_num or date
- How do I reorder (pop and push) items from WP_Query?
- Reverse chronology of post listing
- Automatic value for custom fields for posts
- How do I correctly set up a WP-Query to only show upcoming event-posts?
- Query Posts With Over 1000 Views
- How to order posts by meta_value and title
- Query Posts by Custom Field
- how to get post order by post id wp_query?
- Create a list of posts with topic headdings
- Need to know custom code to display random and most viewed posts in wordpress posts and pages
- WP_Query custom field pass the post id
- Override WordPress core post-template.php block template
- query posts with selected post ids first
- How to get value of a selected option from select tag and use it in WP_query to filter posts?
- How do I display posts ordered by a date custom field?
- Random order of the 5 most popular posts
- My custom query is displaying random posts in random order
- Creating Ordered Query using Meta_key
- Get query result according to merged array
- WP Query between posts custom fields [duplicate]
- Order posts by separate menu order for different sub-categories
- Order by ‘s’ using WP_Query()
- Image inside the content is replaced with featured image from my older post
- Order by Post Title in WP Query not working
- long-title posts do not want published
- How to remove a post from results by ID after query?
- Using a meta_value or postdate to to query and orderby
- Exclude posts in home slider from sections
- Order 2 meta_queries differently in WP_Query?
- Is there a way to save different data when USER interacts with the same POST?
- How do you update post date (year only) in a separate custom field?
- Mix post date with post meta value using WP_Query
- How to use two query result together in one loop
- show loop id post , only first id can read
- WP_Query that targets all categories
- Counting Posts by Category
- Fill the exclude array() in get_posts()
- show image gallery in archives or category page
- Page with Category Returning 1
- The first post appears twice
- filter posts based on menu_order
- Show 5 posts and than 3 posts offset with pagination
- Double loop output
- Change archive results based on GET request
- wp_query args with relation
- Ajaxify Post Sort
- Override wp_link_pages pagebreak with filter
- Get 5 most recent categories
- Loop through all posts showing duplicates
- WP_Query extended with AJAX
- Manipulate query to show specific post
- Wp_query loop is not working as it should
- Get current user, change users post status to published
- Show all posts from the tags without having to set all of them
- Is it possible to query a category with specified posts?
- WordPress text field in array problem
- Allow reader to reorder posts for themselves (oldest first)
- Displaying a specific sub-category’s posts from wp_query
- Is there a global page/post/product/anything ID?
- Auto populate custom fields by post date
- Custom layout manager for posts
- ACF Relationship – Get Parent’s Post Object
- Extracting a TLD from the content and assign to custom field
- Blog only showing one post even though more published
- WordPress loop uses unmodified posts array, why?
- wp query custom orderby not custom field
- How can I set and update the the_date according to a custom field of the post
- Display WordPress Post By Date
- Order Custom Field by Price
- GUID to related post not in current language
- How to make post button to a random post
- How to retrieve a post by inputing the url in a custom field and displaying it on an options page
- Sort / Filter Queries
- Custom fields in normal posts
- Get results from the main wp_query
- Calling specific page with wp query
- How can I display a specific number of post in a category via a url
- Show posts between two Custom Fields date
- get_the_ID() fails the first time, returns a value the second time it’s called
- Query to get data of a post, if in category?
- Order posts by custom field
- Advanced Post Display/Pagination/Ordering
- Where is object, property or label in the database that controls the order of the posts being displayed?
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- How to show the posts list into a static page? Problems to use the loop into a static page
- $args Orderby The number
- How do I control the fallback query after the original query returned cero posts?
- Query category-specific, paginated posts and allow viewer to change sort order
- query_posts with sorting on a custom datestamp
- Remove duplicated posts in the loop if post has more than one category
- Using Post ID and Page ID in same function
- Apply comment to different post (not the current post) [duplicate]
- Pagination for custom query won’t let me back on page 1
- Retrieve latest post by multiple categories with ID
- Adding a category at even positions on main loop with modified pagination
- Displaying Results From Custom Taxonomy Query
- How to only allow post to be deleted if custom field doesn’t exist