@acsnaterse thanks for the suggestion. I will definitely schedule an update.
Awesome! Do you have a slight idea when this would be? We’d happily use the plugin 🙂
Hi @acsnaterse, like you I’m waiting for an update from @aslamdoctor too 🙂
In the meanwhile, where can I find the pre_get_posts filter?
It is in rearrange-woocommerce-products.php (search for it).
But I’d like to mention: we’d strongly advise against editing directly in 3rd party plugins. Better to wait for the update 🙂
Hey guys, I will be posting the updates tomorrow. I am having 5ftf Day tomorrow 👍🏼
@aslamdoctor Thanks Aslam!
Not sure if my issue is related. When I’m using ” Sort by categories ” My category archive is messed up. I see duplicate and missing products. I had to remove and add the categories to the products again.
When not using ” Sort by categories ” my category archive is fine. Instead I filtered the categories in Woocommerce and did the sorting individually.
@acsnaterse thanks for the info. We’re getting an update tomorrow :D.
@acsnaterse I just noticed that below line is already there in the plugin under pre_get_posts hook.
$query->set( 'meta_key', $meta_key );
Check line no 378 here
https://plugins.trac.wordpress.org/browser/rearrange-woocommerce-products/trunk/rearrange-woocommerce-products.php#L378
@aslamdoctor not really. That line is setting the meta_query
, but not the meta_key
.
Adding the line in my example fixes the issue (now it doesn’t 🙂 ).
@acsnaterse ah I see what you mean. I had it in a very initial version of the plugin few years ago. But adding meta_key in query means it will strict the records to load only if that record has meta_key available inside database. So the products with no meta_key for custom sortorder will not show up. So in later versions I had to delete that condition. You can check it under changelogs here https://wordpress.org/plugins/rearrange-woocommerce-products/#developers where it says “VERSION 3.0.2”
Hmm, I get it..
However: the current outcome that it doesn’t sort all the products correctly now 🙂 How do you look at this? Or do you have a fix for that?
Thinking of that: might it be an idea to provide all the products (within a category which is being sorted) with a meta value, so you can sort against it?
Hi guys. Was this ever resolved? We are having the same issue, where, re-arranging by category does nothing, but sorting by product works fine. The issue is that our client has a MASSIVE amount of products, so doing it this way is impossible at the moment.
Any idea when this could be looked at as a proper fix?
thanks for the awesome work on this
Gavin
Well, I understand the issue of the plugin-maker, because by adding the meta_key it will skip products, which don’t have a custom sort meta_key stored.
In our situation we have “fixed” this as following:
Adding this script to your code:
add_action('pre_get_posts', 'custom_change_for_rearrange_products_plugin');
function custom_change_for_rearrange_products_plugin( $query ) {
if ( isset( $_GET['orderby'] ) && 'date' === $_GET['orderby'] ) {
return;
}
if ( is_tax( 'product_cat' ) && $query->is_main_query() && ! is_admin() ) {
$term = get_queried_object();
if( $term ) {
$term_id = $term->term_id;
$meta_key = 'rwpp_sortorder_' . $term_id;
$query->set( 'meta_key', $meta_key );
}
}
}
Step 2 (important!) is to save all the categories once, so you will “force” to have the needed meta_key stored with each product.
wow, thanks for the quick reply and also the fix code. I does not seem to work right away, but perhaps I have some settings that does not correlate with the fix. We are using Divi Woo shop + and ‘Sort by’ is set to default. Should we set the sort by option to date or menu id perhaps?
thanks for the assist
That is something I’d really not know. In our situation this did work, but obviously it might not work in every situation and setup.
But (as far as I know) the plugin overrules the “default” orderby parameters, so why it doesn’t work in your situation, I really don’t know. Best is probably to raise a separate ticket for that.
Thank Acsnaterse – much appreciated!