Created
December 30, 2016 00:46
-
-
Save pixelcutlabs/e00aea4d4df3203653265ab588b41897 to your computer and use it in GitHub Desktop.
Add a new sorting option to FacetWP dropdown
This file contains 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 | |
function register_package_id_default_search_option( $options, $params ) { //We use this section of code (from line 2 to 12) to set up a function but not to use it | |
$options['package_id'] = array( //where package_id is the sorting option Identifier | |
'label' => 'Package ID', //This outputs to the user on the frontend in the FacetWP sorting options dropdown | |
'query_args' => array( //This is how you build a "search" in the SQL database for a specific argument or set of rules | |
'orderby' => 'meta_value_num', // this tells FacetWP that we're looking at the number value of the meta key defined on the next line | |
'meta_key' => '_package_id', // this is the identifier of the custom field we're sorting by | |
'order' => 'DESC', // this makes the highest number come first in results | |
) | |
); | |
return $options; | |
} | |
add_filter( 'facetwp_sort_options', 'register_package_id_default_search_option', 10, 2 ); //This tells WordPress to use the function we created on lines 2-12 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment