Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
John Man

Default sorting not working

I have set some default sorting rules which other than default but it is not working. It worked with last update but no longer with latest update. Seems that the sorting is reseted to wp_posts.post_date DESC. See the query below which is captured with Query Browser.

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
LEFT JOIN wp_postmeta
ON (wp_posts.ID = wp_postmeta.post_id
AND wp_postmeta.meta_key = 'rms_rm_uniq_meta_post_id' )
LEFT JOIN wp_postmeta AS mt1
ON (wp_posts.ID = mt1.post_id
AND mt1.meta_key = 'rms_remote_featured_image' )
WHERE 1=1
AND ( wp_postmeta.post_id IS NULL
AND mt1.post_id IS NULL )
AND wp_posts.post_type = 'shop_order'
AND ((wp_posts.post_status = 'wc-pending'
OR wp_posts.post_status = 'wc-processing'
OR wp_posts.post_status = 'wc-on-hold'
OR wp_posts.post_status = 'wc-completed'
OR wp_posts.post_status = 'wc-cancelled'
OR wp_posts.post_status = 'wc-refunded'
OR wp_posts.post_status = 'wc-failed'
OR wp_posts.post_status = 'wc-price-confirmed'
OR wp_posts.post_status = 'wc-payment-slip'
OR wp_posts.post_status = 'wc-ordered'
OR wp_posts.post_status = 'wc-shipping-to-wh'
OR wp_posts.post_status = 'wc-picked-up'
OR wp_posts.post_status = 'wc-shipping-to-mk'
OR wp_posts.post_status = 'wc-pending-sf'
OR wp_posts.post_status = 'wc-shipping-to-mb'
OR wp_posts.post_status = 'wc-ready-mk-pickup'
OR wp_posts.post_status = 'wc-posted'
OR wp_posts.post_status = 'wc-arrived-mb-wh'
OR wp_posts.post_status = 'wc-mk-transit'
OR wp_posts.post_status = 'wc-to-be-backed'
OR wp_posts.post_status = 'wc-waiting_refund_in'
OR wp_posts.post_status = 'wc-to-be-refunded'))
GROUP BY wp_posts.ID
<strong>ORDER BY wp_posts.post_date DESC</strong>
LIMIT 0, 100

I can see my setting appears in other queries which my preferred sorting. e.g.

SELECT wp_posts.*
FROM wp_posts
LEFT JOIN wp_postmeta
ON (wp_posts.ID = wp_postmeta.post_id
AND wp_postmeta.meta_key = 'rms_rm_uniq_meta_post_id' )
LEFT JOIN wp_postmeta AS mt1
ON (wp_posts.ID = mt1.post_id
AND mt1.meta_key = 'rms_remote_featured_image' )
WHERE 1=1
AND wp_posts.post_name = 'pending'
AND ( wp_postmeta.post_id IS NULL
AND mt1.post_id IS NULL )
AND wp_posts.post_type = 'wc_order_status'
AND ((wp_posts.post_status = 'publish'))
GROUP BY wp_posts.ID
<strong>ORDER BY wp_posts.menu_order ASC</strong>
3 years, 8 months ago
Stefan van den Dungen Gronovius
Developer

Thanks for your input.
Can you check the following for me to make sure that everything is set up correctly?

– Do you see a reset sorting button on top of the overview? The default sorting only applies when there is no custom sorting active on the overview. When you sort on a column, we store that as a user preference, so next time you visit the overview, sorting is still applied on the column. When you click on the ‘Reset Sorting’ button it goes back to the default sorting behavior.

– Based on your input, I suspect that the default sorting for your overview is also o the menu order column? Is that column available on the overview and is the default sorting set to that column?

– Do you not have any other custom code/plugins that also change the sorting behavior of the WP_Query?

3 years, 8 months ago
John Man

– If I have manually sort some column, the “reset sorting” button appears. It is not appearing when I have configured the default sorting.
– Affirmative. The column appears in the overview and it is sortable. I can see the small arrow appears which align to what I set as default sorting, but the column is just not sorting. FYI this is a custom column and it contains only text. (Have you changed anything in the custom column template?)
– Negative. For testing purpose I have put only this column to be sortable.

I have the feel that the problem is related to the new version and the custom column. This column that I have developed was using the “old” template and not the new one with smart filtering. It would be helpful if you can send me the latest template so I can re-code this column to see if this is the solution.

3 years, 8 months ago
Stefan van den Dungen Gronovius
Developer

OK, so sorting does not work at all for your custom column.
Since 5.2 we had a large refactor for sorting so it might indeed be the case that your column is not compatible anymore with that change, although I believe we made it compatible with the column template.

This is the preferred template for a custom column (notice that it is not yet on the master branch):
https://github.com/codepress/ac-column-template/tree/autoloader

I don’t know the background of your column so I can’t advise you on how to sort your column. Can you share your column code with me so I can advise you which modal for sorting to use? Please send any information to support@admincolumns.com

3 years, 8 months ago
John Man

I have tried the new template but no luck. The custom column is just not appearing. I will try again later with other fields.

My field is something text like 07RABCYZ with 0 in the front. It will be changed to 1 in year 2021 and so on so I cannot ignore it. Finally I have changed this field to integer using intval() and seems it works.

3 years, 8 months ago
Stefan van den Dungen Gronovius
Developer

Thanks for the update. I’m glad that it works for now. If you need more help, please let me know.

3 years, 8 months ago

You must be logged in to reply to this topic.