Created
May 15, 2017 21:46
-
-
Save jaredatch/e1ded94ce8286ac03bde6d4f38a346ca to your computer and use it in GitHub Desktop.
WPForms dynamic choices display by category
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 | |
/** | |
* 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