1

I've downloaded Contact Form 7 to add contact forms adding a simple snippet after every post, and I've added it in functions.php like this :

//if post type I add a form

function is_post_type($type)
{
    global $wp_query;
    if($type == get_post_type($wp_query->post->ID)) return true;
    return false;
}

function add_post_content($content){
    if(!is_feed() && !is_home()&& is_single() && is_post_type('post'))
    {
        $content .= '[contact-form-7 id="2202" title="Formulario de contacto 1"]';
    }
    return $content;
}
add_filter('the_content', 'add_post_content');

What I would like to do now is to add a new field in the plugin to send the link of the entry were the user is sending the form, or even to concatenate this link or Id after the email content, or something like that, but I'm stuck in WordPress, and I don't know what file I need to edit and how to import the $post variables.

2 Answers 2

3

This is pretty easy out of the box:

Just use the [_url] special mail tag.

As long as you are on a post or page you can even add some more things like the title with [_post_title].

Just have a look at the documentation for more options.

1

You can try to add a get parameter to your url in the link to your contact form.

If it's a lightbox style, you can also define a hidden field and fill it when wpcf7 loads up using global $post.

Use this code for the url parameter solution and replace id_post by global $post->ID for the lightbow solution :

//Add the post id
function add_post_id_origin ( $tag, $unused ) {
    //First we test if it's our hidden field
    if ( $tag['name'] != 'myhiddentag' )  
    return $tag; 

//This is for the url param version
if(isset($_GET['id_post']) && is_numeric($_GET['id_post']))
{
    $post = get_post($_GET['id_post']);
    $tag['values'] = array($post->ID); 
    $tag['options'] = array('readonly');
}
//this way for a regulare global $post usage
global $post;
$tag['values'] = array($post->ID); 
$tag['options'] = array('readonly');

return $tag;  
}  

//Don't forget to hook the function
add_filter( 'wpcf7_form_tag', 'add_post_id_origin', 10, 2);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.