Replacing select value with title.
-
This is probably a bit of a weird request, and I’ve probably got it backwards, but here goes!
Hopefully someone will be able to help me.
The plan is to automatically fill a select box [select* project-list id:project-list class:project-list include_blank “Unknown”] with custom post type “project” posts, whereby the title in the box is the post name, and the value is the post ID.
function ses_add_project_list_to_contact_form ( $tag, $unused ) { if ( $tag['name'] != 'project-list' ) return $tag; $args = array ( 'post_type' => 'project', 'numberposts' => -1, 'meta_key' => 'wpcf-project-id', 'orderby' => 'date', 'order' => 'DESC' ); $projects = get_posts( $args ); if ( ! $projects ) return $tag; foreach ( $projects as $project ) { $tag['raw_values'] []= $project->ID; $tag['values'] []= $project->ID; $tag['labels'] []= $project->post_title; } return $tag; } add_filter( 'wpcf7_form_tag', 'ses_add_project_list_to_contact_form', 10, 2);The submission (custom post type “sample”is then made the child of the selected “project”, and this post ID value is stored in CFDB for future use.
When the email is sent out, I’d like the email to contain the post title, rather than the value of the select box.
I’m learning my way round wordpress/php, so an explanation in words of one syllable would be great!
The topic ‘Replacing select value with title.’ is closed to new replies.