Title: Adding another ORDERBY for the shortcode
Last modified: August 24, 2016

---

# Adding another ORDERBY for the shortcode

 *  Resolved [ossedk](https://wordpress.org/support/users/ossedk/)
 * (@ossedk)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/)
 * Hello,
 * I’m using your plugin together with the theme Listify.
 * I need to sort the listing by “RATING” – which is a integer hold in $number.
 * How do I go about adding it as orderby, so I can sort a listing by rating and
   do it easy via the short code like:
 * [jobs per_page=”10″ orderby=”**RATING**” show_filters=”false” show_categories
   =”false” categories=”16″ show_pagination=”false”]
 * Let me know, thanks.
 * [https://wordpress.org/plugins/wp-job-manager/](https://wordpress.org/plugins/wp-job-manager/)

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/page/2/?output_format=md)

 *  Thread Starter [ossedk](https://wordpress.org/support/users/ossedk/)
 * (@ossedk)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044769)
 * the rating – is already a customer field. So somehow it would be to sort by that
   custom field – but I have had time figure out how to add this in e.g functions.
   php
 *  Thread Starter [ossedk](https://wordpress.org/support/users/ossedk/)
 * (@ossedk)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044779)
 * Would I be able to do something similiar to:
 *     ```
       $args = array(
       	'orderby'  => 'meta_value',
       	'meta_key' => 'rating',
       	'meta_query' => array(
       		array(
       			'key'     => 'rating',
       			'value'   => null,
       			'compare' => '!='
       		)
   
       	), // End of meta_query
       	'fields'  => 'ID',
       	'exclude' => array(
       		1
       	),
   
       );
       ```
   
 *  Plugin Author [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044843)
 * You’d need to do something like your last post, but hooked into here with a custom
   function to set the args:
 * [https://github.com/mikejolley/WP-Job-Manager/blob/master/wp-job-manager-functions.php#L113](https://github.com/mikejolley/WP-Job-Manager/blob/master/wp-job-manager-functions.php#L113)
 * meta_value_num would also be more suitable.
 *  Thread Starter [ossedk](https://wordpress.org/support/users/ossedk/)
 * (@ossedk)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044867)
 * So just like this ?
 *     ```
       $query_args = apply_filters( 'get_job_listings_query_args', $query_args, $args );
           $args = array(
               'orderby'  => 'meta_value',
               'meta_key' => 'rating',
               'meta_query' => array(
                   array(
                       'key'     => 'rating',
                       'value'   => null,
                       'compare' => '!='
                   )
   
               ), // End of meta_query
               'fields'  => 'ID',
               'exclude' => array(
                   1
               ),
   
           );
       ```
   
 *  Plugin Author [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044869)
 * No, thats not how filters are used. [https://pippinsplugins.com/a-quick-introduction-to-using-filters/](https://pippinsplugins.com/a-quick-introduction-to-using-filters/)
 *  Thread Starter [ossedk](https://wordpress.org/support/users/ossedk/)
 * (@ossedk)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044871)
 * Thanks for the info.
 * I have tried to follow it, can you let me know if I’m getting closer :
 *     ```
       $query_args = apply_filters( 'get_job_listings_query_args', $query_args, $args );
   
           function addRating($query_args){
               $args2 = array(
               'orderby'  => 'meta_value_num',
               'order' => 'DESC',
               'meta_key' => 'rating',
               'meta_query' => array(
                   array(
                       'key'     => 'rating',
                       'value'   => null,
                       'compare' => '!='
                   )
   
               ), // End of meta_query
               'fields'  => 'ID',
               'exclude' => array(
                   1
               ),
   
           );
               	$query_args = array_merge('get_job_listings_query_args', 'addRating');
   
                   return $query_args;
           }
           add_filter( $query_args,'addRating');
       ```
   
 *  Plugin Author [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044872)
 * Afraid not 🙂 Here is a basic function you can start with:
 *     ```
       add_filter( 'get_job_listings_query_args', 'custom_get_job_listings_query_args' );
   
       function custom_get_job_listings_query_args( $args ) {
   
       // Do something to $args here, such as set $args['orderby'] = 'x';
   
       return $args;
       }
       ```
   
 *  Thread Starter [ossedk](https://wordpress.org/support/users/ossedk/)
 * (@ossedk)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044873)
 * Really appreciate your help,
 * Made as simple as possible
 *     ```
       $query_args = apply_filters( 'get_job_listings_query_args', $query_args, $args );
   
           add_filter( 'get_job_listings_query_args', 'custom_get_job_listings_query_args' );
   
       function custom_get_job_listings_query_args( $args ) {
       $args['orderby'] = 'rating';
       return $args;
       }
       ```
   
 * But here I get “Cannot redeclare custom_get_job_listings_query_args() (previously
   declared”
 * What is the mistake on this?
 *  Plugin Author [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044874)
 * The first line in your paste is not needed.
 * And you must have used custom_get_job_listings_query_args() before 🙂 look for
   a same-named function in your code.
 *  Thread Starter [ossedk](https://wordpress.org/support/users/ossedk/)
 * (@ossedk)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044877)
 * I still get the same error after edit the function name
 *     ```
       add_filter('get_job_listings_query_args', 'args_function_rating_dsaw');
   
       function args_function_rating_dsaw( $args ) {
       $args['orderby'] = 'rating';
       return $args;
       }
       ```
   
 * The issue is that the error is stated for the line of the function name.
 *  Thread Starter [ossedk](https://wordpress.org/support/users/ossedk/)
 * (@ossedk)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044878)
 * So to be clear it states it’s alerady declared in the line right under add_filter
 *  Thread Starter [ossedk](https://wordpress.org/support/users/ossedk/)
 * (@ossedk)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044879)
 * it’s somehow because it’s implemented within function get_job_listings( and each
   time this function is called it gets redeclared or that’s at least my assumption.
 *  Thread Starter [ossedk](https://wordpress.org/support/users/ossedk/)
 * (@ossedk)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044881)
 * Got it solved by moving the function outside and declaring it to:
 *     ```
       function args_function_rating_dsaw($args) {
           $args['orderby'] = 'meta_value_num';
           $args['order'] = 'DESC';
           $args['meta_key'] = 'rating';
           return $args;
           }
       ```
   
 * Many thanks for the help!
 *  Plugin Author [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044924)
 * You need to put your code inside functions.php of your theme. I hope that is 
   what you’re doing?
 *  Thread Starter [ossedk](https://wordpress.org/support/users/ossedk/)
 * (@ossedk)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/#post-6044925)
 * Yes of course 🙂
 * But the new function was inside the function get_job_listings_query_args
 * Which made the error of already declared so each time get_job_listings_query_args
   was run it was redeclaring the new function args_function_rating_dsaw – so I 
   moved it outside of get_job_listings_query_args but still in functions.php of
   course:)
 * Works perfectly

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/page/2/?output_format=md)

The topic ‘Adding another ORDERBY for the shortcode’ is closed to new replies.

 * ![](https://ps.w.org/wp-job-manager/assets/icon-256x256.gif?rev=2975257)
 * [WP Job Manager](https://wordpress.org/plugins/wp-job-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-job-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-job-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-job-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-job-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-job-manager/reviews/)

## Tags

 * [orderby](https://wordpress.org/support/topic-tag/orderby/)

 * 20 replies
 * 6 participants
 * Last reply from: [Adam Heckler](https://wordpress.org/support/users/adamkheckler/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/adding-another-orderby-for-the-shortcode/page/2/#post-6045099)
 * Status: resolved