Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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