Skip to content

Instantly share code, notes, and snippets.

@rahularyan
Created November 4, 2017 01:29
Show Gist options
  • Save rahularyan/ce48a3aebc53823937b78cf47ced2f05 to your computer and use it in GitHub Desktop.
Save rahularyan/ce48a3aebc53823937b78cf47ced2f05 to your computer and use it in GitHub Desktop.
<?php
/**
* Filter select field.
*
* Check if select field options are terms and then change orderby and order value.
* This filter will work only with AnsPress 4.1.0
*/
function my_category_field_filter( $args, $form ) {
if ( 'select' === $args['type'] && 'terms' === $args['options'] ) {
$args['terms_args']['orderby'] = 'orderby';
$args['terms_args']['order'] = 'DESC';
}
return $args;
}
add_filter( 'ap_before_prepare_field', 'my_category_field_filter', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment