Created
February 25, 2016 21:30
-
-
Save tripflex/6d5860100a81f847c77b to your computer and use it in GitHub Desktop.
WP Job Manager Job List Custom Sort by Meta Field Value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
Hi,
Can we filter by meta value but still keep featured listings on top?
Br,