Forums › Premium Settings › Orderby Price / Rating on Products post types in results
- This topic has 7 replies, 5 voices, and was last updated 2 years, 4 months ago by
Fabrizio Bevilacqua.
-
AuthorPosts
-
November 1, 2015 at 10:34 pm #47897
Sharon Coleman
MemberHave been stuck on this for some time.
I would like to have visitors able to order their search results by price and by rating.
The results are woocommerce products.
I can add the filter to the search form to narrow down the price BETWEEN, and I have orderby post_date / post_title working fine, but orderby price is beyond me it seems.
Have tried a few thing by adapting the example coding given here – http://docs.tempform.wpengine.com/posts-locator-order-by-filter/
like
elseif ( $orderby_value == ‘price’ ) {
$meta[‘key’] = ‘_regular_price’;
$clauses[‘orderby’] = ‘meta_value_num’ => ‘ASC’; }$clauses[‘orderby’]= $wpdb->prefix.’postmeta.meta_key => _regular_price’, ‘meta_value-num’;
but just end up with a blank screen.I assume that being able to have BETWEEN working means that it must be possible, I just am not good enough with WP/PHP to figure out how it works.
Any help would be appreciated.
Sharon
November 4, 2015 at 3:10 am #48089Sharon Coleman
MemberThinking about this – if an orderby price isn’t possible – then if the BETWEEN numerical custom fields section could be displayed as a slider then that would be a good compromise.
December 6, 2015 at 4:03 am #49363bigint
MemberHi Sharon,
I need to do exactly the same, ‘Order WooCommerce products in the search results list by price low to high’. Did you manage to make this work please? If so, are you happy to share your code with me please?
Thanks,
Daniel.
January 22, 2016 at 4:48 am #50230Chris Homan
MemberI was trying to do the same and I think I got it to work 🙂
This is the code I used (snapped from the posts locator dropdown example:
1234} elseif ( $orderby_value == 'price' ) { // make sure it's set to same in dropdwon$clauses['join'] .= " LEFT JOIN {$wpdb->prefix}postmeta AS pmeta ON({$wpdb->prefix}posts.ID = pmeta.post_id AND pmeta.meta_key = '_regular_price')"; //replace with whatever your meta key is$clauses['orderby'] = "pmeta.meta_value ASC"; //change to DESC to reverse order}I attached a file which contains the complete code – the content has to be added to your functions.php file
Attachments:
You must be logged in to view attached files.January 24, 2016 at 11:03 am #50251bigint
MemberHi Chris,
Thank you, so much. I put this on the back burner, until my PHP skills improved. I manage to create the odd WordPress filter and hook but I am not expert at PHP. I haven’t tried your code yet, but I am going to, hopefully tomorrow.
I’ll feed back.
Thanks again.
August 13, 2019 at 8:19 am #59448nickisyourfan
MemberI know its 3 year later.. But mine only sorts by distance. Nothing else.
March 25, 2020 at 7:21 am #60026Fabrizio Bevilacqua
MemberHi,
I am able to set it only for distance, post_title, ID ( post ID ), post_date ( date created ), post_modified ( last modifed ) and post_type.
I am trying to set the order by average rating and price of my products, with Geo my WP premium setting extension, but at the moment I don’t have any success. Do you have some news on it?
I also need to show the customer review per product under the name of each product. Someone of you know something about it?
Thank you in advance.
March 25, 2020 at 7:32 am #60027Fabrizio Bevilacqua
MemberHi,
I tried the code by @Chris Homan and it has function very well.
But at the moment I am not able to show the rating under the name of each product in the list of searching results.Someone can help me?
Thank you
-
AuthorPosts
You must be logged in to reply to this topic.