Support » Plugin: Contact Form 7 » [Plugin: Contact Form 7] Possible To Make A Drop Down Selector That Lists WordPress Categories?

  • rishel


    Have a question for anyone that can spare a moment. We use the Contact Form 7 Plugin, and on our “Submit Company News” Page located at we are wanting to add a field “Desired Press Release Category” which would be a drop down box that lists the existing categories (which can be seen in the right side, the categories widget).

    Is this possible?

Viewing 3 replies - 1 through 3 (of 3 total)
  • mark_weston



    I’ve done something similar. Check out this posting:

    What I’m still working on is how to dynamically populate the checkbox field.




    Mark, thanks so much for your reply. However, it is well over my head, I did read your post though. I thought perhaps it might be simpler, but I was wrong.

    I do not do that type of coding, so deployment for me would be much harder. I can edit, and code some, but not that deep.

    Unless I am missing something? Is it a matter of editing a certain file with some code or adding code?




    If you want to just create an email from the form and you then manually copy/pasto that information into a new post then all you need to add to your form is:


    What I am doing is using a CF7 form to create a page automatically – saves on all that copy paste. I’m not that much of a developer/programmer either – I just used what I could find on the internet.

    The form uses a checkbox to identify the category. You could just as easily use a drop down list box.

    I then use the code in functions.php (one of your theme files) to then create the page (or it could be a post).

    In your case it could be something like this:

    Contact Form
    ‘<p><b>Your Name</b> (Required)

    [text* your-name 75/] </p>

    <p><b>Your Company Name</b> (Required)

    [text* your-company-name 75/] </p>

    <p><b>Your Phone Number</b> (Required)

    [text* your-phone-number 75/] </p>

    <p><b>Your Email</b> (Required)

    [email* your-email 75/] </p>

    <p><b>Company News Title</b> (Required)

    [text* company-news-title 75/] </p>

    <p><b>Company News Content</b> (Required)

    [textarea* company-news-content 76×20] </p>

    <p><b>Company News Category</b> (Required)


    <p>[submit “Send”]</p>’

    ‘remove_all_filters (‘wpcf7_before_send_mail’);
    add_action( ‘wpcf7_before_send_mail’, ‘contactform7_before_send_mail’ );

    function contactform7_before_send_mail( $cf7 ) {

    // Submit Company News
    if ( 1 == $cf7->id ) { // this is the id of the contact form

    $your_name = $cf7->posted_data[“your-name”];
    $your_company_name = $cf7->posted_data[“your-company-name”];
    $your_phone_number = $cf7->posted_data[“your-phone-number”];
    $your_email = $cf7->posted_data[“your-email”];
    $company_news_title = $cf7->posted_data[“company-news-title”];
    $company_news_content = $cf7->posted_data[“company-news_content”];
    $company_news_category = $cf7->posted_data[“company-news-category”];

    $categories = array();
    $categories[] = 17; // this is the id of the company news category
    foreach ($company_news_category as $the_category) {
    $categories[] = get_cat_ID($the_category);

    $my_post = array();
    $my_post[‘post_title’] = $company_news_title;
    $my_post[‘post_content’] = $company_news_content;
    $my_post[‘post_status’] = ‘draft’;
    $my_post[‘comment_status’] = ‘open’;
    $my_post[‘ping_status’] = ‘closed’;
    $my_post[‘post_author’] = 1;
    $my_post[‘post_category’] = $categories;
    $new_post_id = wp_insert_post( $my_post );

    update_post_meta($new_post_id, ‘Your_Name’, $your_name);
    update_post_meta($new_post_id, ‘Your_Phone_Number’, $your_phone_number);
    update_post_meta($new_post_id, ‘Your_Email’, $your_email);

    The only tricky part is making sure the category descriptions match up.


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Contact Form 7] Possible To Make A Drop Down Selector That Lists WordPress Categories?’ is closed to new replies.