• Resolved konsument

    (@konsument)


    Hey,
    Im using a custom tag with wpcf7_add_form_tag. But it doesnt show up in “select field” dropdown. What am I missing?

    functions:

    add_action( 'wpcf7_init', 'custom_views_post_title' );
     
    function custom_views_post_title() {
        wpcf7_add_form_tag( 'custom_views_post_title', 'custom_views_post_title_shortcode_handler' );
    }
     
    function custom_views_post_title_shortcode_handler( $tag ) {
        global $post;
        $args = array( 'post_type' => 'myposttype',
          'orderby' => 'date', 
          'order' => 'DESC',
          'posts_per_page' => -1 );
        $myposts = get_posts( $args );
        $output = '<select name="jobs" class="jobselect" autocomplete="off"><option value="Bitte w&auml;hlen">Bitte w&auml;hlen</option>';
        foreach ( $myposts as $post ) : setup_postdata($post);
    	   $title = get_the_title();
    	   $id = get_the_ID();
    	   $output .= '<option value="'. $title .'">'. $title .' </option>';
    
    	endforeach;
        $output .= "</select>";
        return $output;	
    
    }

    my shortcode:

    [custom_views_post_title]

    • This topic was modified 7 years, 2 months ago by konsument.
    • This topic was modified 7 years, 2 months ago by konsument.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jules Colle

    (@jules-colle)

    I’ll look into it further, but I think the main problem is that your field does not have a name as far as CF7 is concerned. I see you create a name hard-coded in the shortcode,

    but you would need to pull it dynamically and use your shortcode like this:

    [custom_views_post_title jobs]

    This way, if all is implemented correctly, you would see a field named “jobs” in the dropdown list.

    Thread Starter konsument

    (@konsument)

    yeah, I already tried that, but it still wont show up. BTW: it works in my email template.

    • This reply was modified 7 years, 2 months ago by konsument.
    Thread Starter konsument

    (@konsument)

    Got it: ‘array(‘name-attr’ => true)’ did the trick.

    wpcf7_add_form_tag( 'custom_views_post_title', 'custom_views_post_title_shortcode_handler', array( 'name-attr' => true ));

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘custom tag not showing up in — Select field —’ is closed to new replies.