Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Created May 15, 2017 21:46
Show Gist options
  • Save jaredatch/e1ded94ce8286ac03bde6d4f38a346ca to your computer and use it in GitHub Desktop.
Save jaredatch/e1ded94ce8286ac03bde6d4f38a346ca to your computer and use it in GitHub Desktop.
WPForms dynamic choices display by category
<?php
/**
* Narrow down post displayed by category.
*
* See https://codex.wordpress.org/Template_Tags/get_posts
*
* @param array $args
* @param array $field
* @param int $form_id
* @return array
*/
function wpf_dynamic_choices_categories( $args, $field, $form_id ) {
// For field #4 in form #10, only show entries in category #5
if ( '10' == $form_id && '2' == $field['id'] ) {
$args['category'] = '5';
// For field #2 in form #11, only show entries in category #6
} elseif ( '11' == $form_id && '2' == $field['id'] ) {
$args['category'] = '6';
}
return $args;
}
add_filter( 'wpforms_dynamic_choice_post_type_args', 'wpf_dynamic_choices_categories', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment