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
- The next_posts_link() works only with original $wp_query
- Different post sort order within different categories
- WP_Query: Why is sticky post not first item in loop?
- Query *only* sticky posts
- Skipping first 3 posts in wp query
- meta_box or custom_field as a second tinymce post-instance?
- Set number of article per number of page
- Get only modified posts
- Create A Metabox For A Custom Field
- How to choose a sort order (for posts) per category? (ideally when creating a new category)
- Should ‘setup_postdata()’ be reset with ‘wp_reset_postdata()’?
- Sanitizing `wp_editor();` Values for Database, Edit, and Display
- Hide Post comments when displayed via WP_Query
- orderby=meta_value_num creates duplicate posts
- Custom fields on a virtual page
- posts_per_page doesnt work
- Get a custom field of all posts on current blog page
- Display posts in alphabetical order for a particular category
- How can I get a post field value using javascript?
- Improving WP_Query for performance when random posts are ordered
- Why won’t my taxonomy query show up?
- WP_Query with ajax handler returns the same posts
- Hiding Draft Post In Admin
- How to verify wp user password by sql query in wp? [closed]
- Sort WP posts by span value
- Automatically add custom fields value to wordpress post
- How to filter my search in post if contains a word in title, content or excerpt?
- How to sort posts inside categories
- Lost draft under all posts and drafts
- Get user categories with most posts in it
- Random ajax load only works with posts_per_page set to -1
- Query posts and return XML
- List authors with the last post title and order by last post date
- Hooking into the post editing screen for an existing page only
- Adding a blog archive with pagination using WP_Query
- How to get Tags with specific post id
- WordPress query_posts by tag doesn’t work anymore(?)
- Ignore latest two posts
- Print out last 3 blogposts
- How can I add a box to edit Order on a regular post?
- How to group only VISIBLE posts? [closed]
- Shortcode with ‘year’ parameter
- On what hook can I get the queried object’s final state?
- Add two custom fields as a default to the “new post” page.
- Get all custom posts with a certain taxonomy
- Link to date_query results in WordPress
- Query function not executed between element [closed]
- When WP_Query only returns 1 post, how do I automatically redirect to that post?
- Limiting post list by taxonomy
- Will multiple category descriptions effect my search engine optimization?
- How Can I Always Display A Particular Post First Using WP_Query?
- Post picker custom field on page
- Function is printing twice – any suggestions?
- Order posts inside bootstrap card columns
- How to use two query result together in one loop
- show loop id post , only first id can read
- filter posts based on menu_order
- Change archive results based on GET request
- Wp_query loop is not working as it should
- Show all posts from the tags without having to set all of them
- Is there a global page/post/product/anything ID?
- Auto populate custom fields by post date
- ACF Relationship – Get Parent’s Post Object
- wp query custom orderby not custom field
- Order Custom Field by Price
- Calling specific page with wp query
- $args Orderby The number
- Retrieve latest post by multiple categories with ID
- The next_posts_link() works only with original $wp_query
- Limit amount of pages shown in pagination within wp_query
- How to make a local “scroll to ID” on post?
- Show Title/Date/Excerpt of first post & only Title for rest in Query [duplicate]
- Get posts after calculating meta key
- Custom Admin Post Column change order
- Get related posts matching most of the provided tags using WP_Query