• Resolved ossedk

    (@ossedk)


    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://ww.wp.xz.cn/plugins/wp-job-manager/

Viewing 15 replies - 1 through 15 (of 20 total)
  • Thread Starter ossedk

    (@ossedk)

    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

    (@ossedk)

    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

    (@mikejolley)

    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

    meta_value_num would also be more suitable.

    Thread Starter ossedk

    (@ossedk)

    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

    (@mikejolley)

    Thread Starter ossedk

    (@ossedk)

    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

    (@mikejolley)

    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

    (@ossedk)

    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

    (@mikejolley)

    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

    (@ossedk)

    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

    (@ossedk)

    So to be clear it states it’s alerady declared in the line right under add_filter

    Thread Starter ossedk

    (@ossedk)

    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

    (@ossedk)

    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

    (@mikejolley)

    You need to put your code inside functions.php of your theme. I hope that is what you’re doing?

    Thread Starter ossedk

    (@ossedk)

    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)

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