NooTheme Premium WordPress Theme › Forums › CitiLights › Add order by price
- This topic has 8 replies, 2 voices, and was last updated 6 years, 1 month ago by
Kan Nguyen.
-
AuthorPosts
-
6 years, 2 months ago #1858
Hi,
I need to show properties ordered by price, ascending or descendig (it could be interesting to add another box filter with this concept sort by - ascending - descending). With that I could ordered properties by price, by date, by name...
Is there any way to do this?
Thanks in advance!!
6 years, 2 months ago #1884Hello,
There's only one way to get it is to customize the source code, if you can edit PHP code, I'll tell you where to change the code.
Best regards,
Kan Nguyen
6 years, 2 months ago #2013Hi again,
I just want to notice you that the order by price is added to the latest version ( 1.6.2 ), but there's no additional box for ASC or DESC yet.
Best regards,
Kan Nguyen
6 years, 2 months ago #2078<div>
<div>
<div>
<div>
<div>Hi Kan,It's a good news, I was worried about this and my customer too!!</div>
</div>
But, how must install new version without losing all changes I did in the site(css, translations names, etc...)?</div>
</div>
Is possible only change especific files? If it is possible what files?I supose the results of the filter have a predeterminate order , ascendent or descendent, Could you indicate where I could add box with asc or desc?? I comment you, we can not problem in edit php.</div>
<div></div>
<div>Thanks in advance for your help!!</div>
<div></div>
Núria6 years, 2 months ago #2110So I'll instruct you to edit code to add price order and asc or desc:
All the code is in file: noo-citilights/framework/admin/noo-property.php
1. Function pre_get_posts, you will see there's a switch case orderby, add this case for price:<code>case 'price' : $args['orderby'] = "meta_value_num {$wpdb->posts}.ID"; $args['order'] = $order == 'DESC' ? 'DESC' : 'ASC'; $args['meta_key'] = '_price'; break;</code>
also in that function, please change
$order = 'DESC'
to$order = isset($_GET['orderby']) ? $_GET['order'] : 'DESC'
to recognize the value from GET.2. Function display_content
This function include html for property listing, you will see at the start of html code, there's Sorted by dropdown. Please add
'price'=>__('Price',NOO_TEXT_DOMAIN),
to the$order_arr
array. This will add sort by price.To add ASC or DESC, please add a dropdown, checkbox or radio list also in that area. I think it's easy for you, just remember to use the same field name 'order' as the _GET value above.
Best regards,
Kan Nguyen
6 years, 2 months ago #2156Hi Kan,
I tested in properties in general and it works, but not works in rent o sale properties, status or type. I realize that In your theme
http://wp.nootheme.com/citilights/
if you try to order by price or bathroms or bedroms (not only for price with other don't work neither) in menu item properties-> status: rent or sale or types: apartment, condo, etc , they don't work.
How can we fix the problem??Thanks in advance
6 years, 1 month ago #2173Hi,
I found a bug regarding it, I'll add the fix to the next update. You can add this fix yourself by following my instruction.
1. Add this function into file noo-property.php:
<code>public static function is_noo_property_query( $query = null ) { if( empty( $query ) ) return false; if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] === 'noo_property' ) return true; if( $query->is_tax ) { if( ( isset( $query->query_vars['property_category'] ) && !empty( $query->query_vars['property_category'] ) ) || ( isset( $query->query_vars['property_status'] ) && !empty( $query->query_vars['property_status'] ) ) || ( isset( $query->query_vars['property_location'] ) && !empty( $query->query_vars['property_location'] ) ) || ( isset( $query->query_vars['property_sub_location'] ) && !empty( $query->query_vars['property_sub_location'] ) ) ) { return true; } } return false; }</code>
2. In function pre_get_posts, please change the line for checking noo_property query from:
if(isset($q->query_vars['post_type']) && $q->query_vars['post_type'] === 'noo_property')
to:
if( self::is_noo_property_query( $q ) )
Let me know if it resolve your problem.
Best regards,
Kan Nguyen
6 years, 1 month ago #2196Hi Kan,
it works perfectly!!
Thanks a lot!!
6 years, 1 month ago #2247Great! Now I know it'll work on the next version.
Best regards,
Kan Nguyen
-
AuthorPosts
You must be logged in and have valid license to reply to this topic.