• Resolved anggunpribadi

    (@anggunpribadi)


    Hi, Konichiwa Miyoshi san.

    Im developing a wordpress site and using your really great Contact Form 7, i have a question, can i create a custom shortcode to used in the form editor, i just created my own shortcode function and use add_shortcode wordpress hook, but when i add it in the form editor it doesn’t work.
    fyi, i want to create a dropdown for a product custom post type, so the shortcode will looks like [product].

    Thanks,

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter anggunpribadi

    (@anggunpribadi)

    Okay, just find it it should be in wpcf7_add_shortcode hook.

    Thanks anyway for the great plugin.

    Could you explain how you did it? I want to do something like that, but by populating the dropdown with categories.

    Here is some code that i created and works!

    wpcf7_add_shortcode('postdropdown', 'createbox', true);
    function createbox(){
    global $post;
    $args = array( 'category' => 5 );
    $myposts = get_posts( $args );
    $output = "<select name='cursus' id='cursus' onchange='document.getElementById(\"cursus\").value=this.value;'><option></option>";
    foreach ( $myposts as $post ) : setup_postdata($post);
    	$title = get_the_title();
    	$output .= "<option value='$title'> $title </option>";
    
    	endforeach;
    $output .= "</select>";
    return $output;
    }

    With the shortcode [postdropdown cursus] in the contactform to show posts from category 5. Put shortcode [cursus] in the mailtemplate.

    cheers.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to add new custom shortcode’ is closed to new replies.