Skip Navigation

[Resolved] Sorting of products not working on view

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user would like to sort a view using a taxonomy.

Solution:
That's not possible without custom code to change the underlying SQL query. Because the WP_Query class does not offer this feature.

For a custom code solution, check this example http://scribu.net/wordpress/sortable-taxonomy-columns.html

https://wordpress.stackexchange.com/questions/14306/using-wp-query-is-it-possible-to-orderby-taxonomy

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 11 replies, has 2 voices.

Last updated by Rob 3 years, 7 months ago.

Assisted by: Jamal.

Author
Posts
#2093281

Rob

Tell us what you are trying to do?
I am trying to use the same sorting order on the page hidden link on the page hidden link
The sorting doesn't seem to have any effect on this page. i am using 2 different reusable blocks.

Is there any documentation that you are following?
No

Is there a similar example that we can see?
hidden link

What is the link to your site?
hidden link

#2093617

Hello and thank you for contacting Toolset support.

I don't believe that using Reusable blocks should alter the sorting of a view, especially if the reusable blocks are being used inside the loop. To better assist you with this issue, I'd like to get access to your website and check how both views are built. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

It would be helpful if you start with a compatibility test to make sure nothing else is interfering there. Please check if this sorting issue appears when:
- Only Toolset plugins are activated. It will tell us if there is an interaction issue with another plugin.
- The theme is set to a WordPress default like Twenty-Twenty. It will tell us if there is an interaction issue with your theme.
If the problem disappears, start activating one at a time to track where the incompatibility is produced.

#2094369

At first sight, I thought that you are sorting the view with the product price. It turns out that you are sorting the view in the first page using the post type. Check this screenshot hidden link

The view on the second page has a sorting on the menu order, which is different from the first one. Check this screenshot hidden link

I am not sure what type of sorting you want to have, so I'll let you choose it by yourself. Let me know if you still need assistance on this.

#2094521

Rob

Thanks for your quick reply. That is correct, changing it to anything doesn't seem to have effect. I tried setting it to post type, but still it doesn't sort like the first page...

#2094639

Well, the first page is ordered by post type. Maybe it is just a coincidence that it has prices sorted. The second page is now sorted by menu_order, then by post_title.

What sorting do you want to have? By price? By title? Because as of now, I can only guess.

#2094777

Rob

I changed the block of the second page (with problem) to sort by post type as well. Right(first) page is (hidden link) I want to show woocommerce products sorted by category, which are selected by the category filter... Does this mean I should sort by post type?
I changed it to post type as well, but the sorting doesn't show the expected sorted results...

#2095843

Well, the post type for products is "product". Basically, almost everything in WordPress is actually a post. Pages are posts from the post type "page". Regular posts are from the post type "post". Media files are stored as a post-type "attachment".
Toolset lets you create your own post types. And you can see all the registered post types in Toolset->Dashboard(the default types, the types registered by the theme or other plugins, and the types created using Toolset).

Now, regarding the sorting of products by their categories, that is not possible out of the box from WordPress/Toolset. It may be implemented, but it will need custom code. Check this StackExchange discussion https://wordpress.stackexchange.com/questions/14306/using-wp-query-is-it-possible-to-orderby-taxonomy
And the custom code in this article hidden link

Please note that custom code is beyond the scope of Toolset Support. If you are not comfortable with programming, you may need to hire a developer.
- https://toolset.com/toolset-support-policy/
- https://toolset.com/contractors/

I hope this helps. Let me know if you have any questions.

#2095919

Rob

Thanks for your reply. Why does it work for the sorting work for this page hidden link and not for the other one?

#2095923

I believe it is just a coincidence that it works for this page:
hidden link

This is the underlying SQL query for that view, check this screenshot hidden link

SELECT   wp_posts.* FROM wp_posts  LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1  AND ( 
  wp_term_relationships.term_taxonomy_id IN (19,21,22,23,24,25,27,30,39,48)
) AND wp_posts.post_type = 'product' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_type ASC 

As you can see, at the end of the query, the sorting is done on the post_type:

ORDER BY wp_posts.post_type ASC 
#2097817

Rob

Is there a way to manipulate the query to change the taxonomy_id order?

#2098913

The taxonomy order cannot be changed using the WP_Query class, which Toolset uses for the views' queries. It will require custom code. Check this StackExchange discussion https://wordpress.stackexchange.com/questions/14306/using-wp-query-is-it-possible-to-orderby-taxonomy
And the custom code in this article hidden link

#2100725

Rob

Thank you very much for your (quick) assistance looking for a solution regarding the issue! I have enough knowledge now regarding this issue and possible fixes!
Have a nice day 🙂