Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created February 25, 2016 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tripflex/6d5860100a81f847c77b to your computer and use it in GitHub Desktop.
Save tripflex/6d5860100a81f847c77b 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 );
@giangledev
Copy link

Hi,

Can we filter by meta value but still keep featured listings on top?

Br,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment