PHP sort guidance required
-
As I’m not very strong on PHP, I thought I’d ask here for some help.
I’m trying to find a way sort an array in a wordpress theme (theme designers say they don’t provide help on customising themes).
The current default sort is set to post_date (as indicated in code below), I need to update the php to sort either by post_date or car_price or car_mileage or car_year, depending upon what has been selected on front page.
Problem is I haven’t the first notion of how I would go about doing this!
a demo is at demo
Here’s my partial code from the WP theme:
//************************************************************************************************* $orderby_array = array( 'post_date' => __( "Post date", 'cardealer' ), 'car_price' => __( "Price", 'cardealer' ), 'car_mileage' => __( "Mileage", 'cardealer' ), 'car_year' => __( "YOR", 'cardealer' ), ); $orderby = 'post_date'; <=== Change this value to anyone in the above array. if ( isset( $_GET['orderby'] ) ) { $orderby = $_GET['orderby']; } $order = 'DESC'; if ( isset( $_GET['order'] ) ) { $order = $_GET['order']; } . . . . . . . <div class="page-header sorting clearfix"> <div class="sort-by"><?php _e( "Sort by:", 'cardealer' ) ?></div> <ul class="sort-by-list"> <?php foreach ( $orderby_array as $key => $value ): ?> <li class="<?php echo ( $orderby == $key ) ? 'active' : '' ?>"> <a href="javascript:void(0);" class="js_order_cars_by order_cars_by search_order_<?php echo strtolower( $order ) ?>" data-orderby="<?php echo $key ?>" data-order="<?php echo( $order == 'DESC' ? 'ASC' : 'DESC' ) ?>" <?php echo strtoupper( $value ) == 'YOR' ? 'title="Year of registration"' : ''; ?>> <?php echo $value ?> </a> </li> <?php endforeach; ?> </ul> <!--/ .sort-by-list-->
- The topic ‘PHP sort guidance required’ is closed to new replies.