Support » Plugin: Contact Form by WPForms - Drag & Drop Form Builder for WordPress » Exclude pages from Dynamic Choices

  • Resolved freshned

    (@freshned)


    Hi,

    I use your plugin and the Dynamic Choices option with post-types and pages as chosen option. But in the dropdown list there are also pages like home and about us. Is it possible to exclude those pages and only show my car pages.

    I hope someone can help with this.

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jared Atchison

    (@jaredatch)

    Hey freshned,

    Thanks for reaching out!

    You are in luck – we have a filter in place just for this 🙂

    apply_filters( 'wpforms_dynamic_choice_post_type_args', $args, $field, $form_data['id'] )

    Below is an example using that filter (this would be placed in you theme’s functions.php file or similar). In this example, we’re only changing the options for field #1 in form #5.

    
    /**
     * Exclude pages from dynamic choices.
     *
     * @param array $args
     * @param array $field
     * @param int $form_id
     * @return array
     */
    function wpf_dynamic_choices_exclude( $args, $field, $form_id ) {
    	
    	if ( '5' == $form_id && '1' == $field['id'] ) {
    		$args['exclude'] = '55,71';
    	}
    
    	return $args
    }
    add_filter( 'wpforms_dynamic_choice_post_type_args', 'wpf_dynamic_choices_exclude', 10, 3 );
    

    Hope that helps 🙂

    Hi Jared,

    Thank you for your reply and help. The field id i like to change is 4.
    Form id is 764 and the pages (id) I like to exclude from the dropdown are 7, 349 and 722.

    Are this the numbers I need to add to the code above and what do I need to change.

    Because I get an error when I add the second script to my functions.php.

    Thank you! I will wait for your response.

    Plugin Author Jared Atchison

    (@jaredatch)

    Sorry about tat, I was misisng a semicolon on one of the lines which was causing the error.

    Try the snippet below. The numbers have been adjusted per above!

    
    /**
     * Exclude pages from dynamic choices.
     *
     * @param array $args
     * @param array $field
     * @param int $form_id
     * @return array
     */
    function wpf_dynamic_choices_exclude( $args, $field, $form_id ) {
    
    	if ( '764' == $form_id && '4' == $field['id'] ) {
    		$args['exclude'] = '7,349,722';
    	}
    
    	return $args;
    }
    add_filter( 'wpforms_dynamic_choice_post_type_args', 'wpf_dynamic_choices_exclude', 10, 3 );
    
    freshned

    (@freshned)

    Hi Jared,

    Thank you for you fast reply. It works perfectly! Thank you very much.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.