Search
 
SCRIPT & CODE EXAMPLE
 

PHP

contact form dropdown from post

add_action( 'wpcf7_init', 'custom_add_form_tag_customlist' );

function custom_add_form_tag_customlist() {
    wpcf7_add_form_tag( array( 'customlist', 'customlist*' ), 
'custom_customlist_form_tag_handler', true );
}

function custom_customlist_form_tag_handler( $tag ) {

    $tag = new WPCF7_FormTag( $tag );

    if ( empty( $tag->name ) ) {
        return '';
    }

    $customlist = '';

    $query = new WP_Query(array(
        'post_type' => 'CUSTOM POST TYPE HERE',
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'orderby'       => 'title',
        'order'         => 'ASC',
    ));

    while ($query->have_posts()) {
        $query->the_post();
        $post_title = get_the_title();
        $customlist .= sprintf( '<option value="%1$s">%2$s</option>', 
esc_html( $post_title ), esc_html( $post_title ) );
    }

    wp_reset_query();

    $customlist = sprintf(
        '<select name="%1$s" id="%2$s">%3$s</select>', $tag->name,
    $tag->name . '-options',
        $customlist );

    return $customlist;
}

//use this tag in your form
//[customlist your-field-name]


Comment

PREVIOUS NEXT
Code Example
Php :: remove number after decimal in php 
Php :: dd function not laravel 
Php :: How to display limited post content in WordPress 
Php :: morph laravel without classes name 
Php :: Store authentication status in a cookies 
Php :: ipay generate hash id 
Php :: php hook function 
Php :: quitar elemento array php 
Php :: how to override category product from seo title and description 
Php :: strtotime last day of month 
Php :: php count word arabic 
Php :: leaf php 
Php :: Pasar el email de recuperar contraseña de laravel a español 
Php :: php unit testAdd Answer 
Php :: php: foreach loop 
Php :: Expected response code 250 but got code "530", with message "530 Must issue a STARTTLS command first. " 
Php :: hide .php 
Php :: php boolean 
Php :: display picture in pdf generated with laravel 
Php :: Write a php program to swap two numbers using temporary variable 
Php :: Attempt to read property "name" on bool 
Php :: carbon check sunday 
Java :: java get screen size 
Java :: java get class by string 
Java :: rgb to hex java 
Java :: find maven version 
Java :: seconds to hours java 
Java :: center justify jlabel 
Java :: java lerp 
Java :: array to map java3 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =