Skip to content

Instantly share code, notes, and snippets.

@pije76
Forked from tripflex/functions.php
Created February 2, 2020 09:56
Show Gist options
  • Save pije76/cfb4730931c78fd76d4b87bca0a3e984 to your computer and use it in GitHub Desktop.
Save pije76/cfb4730931c78fd76d4b87bca0a3e984 to your computer and use it in GitHub Desktop.
WP Job Manager Job List Custom Sort by Meta Field Value
<?php
// https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
function xyz_custom_orderby( $query_args ) {
// Use meta_value_num for numeric sorting (if issues with meta_value)
$query_args[ 'orderby' ] = 'meta_value';
$query_args[ 'order' ] = 'ASC';
return $query_args;
}
add_filter( 'job_manager_get_listings_args', 'xyz_custom_orderby', 99 );
function xyz_custom_orderby_query_args( $query_args ) {
$query_args[ 'cache-bust' ] = time();
$query_args[ 'meta_key' ] = '_job_salary'
return $query_args;
}
add_filter( 'get_job_listings_query_args', 'xyz_custom_orderby_query_args', 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment