• Resolved jeroenduller

    (@jeroenduller)


    Hi,

    Can someone please help me to create a dropdown select list in Contact Form 7 to select a published Post.
    I want to use this in a job application so a specific Job (blog post) can be selected.

    I am not a programmer, so if somebody can take this as a job, please let me know.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author John Huebner

    (@hube2)

    If you’re not a coder I would suggest looking for a plugin that does not require coding. This is a good one https://wpforms.com/

    Not sure if there is a rule about posting jobs here, but if you’re looking for someone to hire you should probably look at one of the popular freelancing sites.

    Here is a quick example using my example code

    
    function cf7_dynamic_select_published_posts($choices, $args=array()) {
        $args = array(
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => -1,
        );
        $query = new WP_Query($args);
        $choices = array();
        if ($query->have_posts()) {
          global $post;
          while ($query->have_posts()) {
            $query->the_post();
            $choices[get_the_title()] = get_the_title();
          }
          wp_reset_postdata();
        }
        return $choices;
    } // end function cf7_dynamic_select_do_example1
    add_filter('wpcf7_dynamic_published_post_select', 
                 'cf7_dynamic_select_published_posts', 10, 2);
    

    Hey,

    I need exact the same dropdown solution. Unfortuantely if there are posts with the same title it only display one of that title. In my example I got a lot of “Lorem Ipsum”-titles where only one shows up. Whats wrong there?

    function cf7_dynamic_select_jobs($jobs, $args=array()) {
        $args = array(
          'post_type' => 'jobs',
          'orderby' => 'date', 
          'order' => 'DESC',
          'posts_per_page' => -1
        );
        $query = new WP_Query($args);
        $jobs = array();
        if ($query->have_posts()) {
          global $post;
          while ($query->have_posts()) {
            $query->the_post();
            $jobs[get_the_title()] = get_the_title();
          }
          wp_reset_postdata();
        }
        return $jobs;
    }
    add_filter('show_jobs', 'cf7_dynamic_select_jobs', 10, 2);

    This will give you a dynamic drop-down select list

    Select Options from database for Contact Form 7

    https://www.ads-software.com/plugins/select-options-from-database-for-contact-form-7/

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Dropdown list with Post titles in contact form’ is closed to new replies.