Skip to content

Instantly share code, notes, and snippets.

@pixelcutlabs
Created December 30, 2016 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixelcutlabs/e00aea4d4df3203653265ab588b41897 to your computer and use it in GitHub Desktop.
Save pixelcutlabs/e00aea4d4df3203653265ab588b41897 to your computer and use it in GitHub Desktop.
Add a new sorting option to FacetWP dropdown
<?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