Contact Form 7
[resolved] How to add new custom shortcode (4 posts)

  1. anggunpribadi
    Posted 5 years ago #

    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].


  2. anggunpribadi
    Posted 5 years ago #

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

    Thanks anyway for the great plugin.

  3. Jack
    Posted 5 years ago #

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

  4. wzshop
    Posted 4 years ago #

    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>";
    $output .= "</select>";
    return $output;

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


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Contact Form 7
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic