ttn*_*tn_ 5 contact-form-7 shortcode
我有 2 个由联系表单 7 创建的联系表单。如何列出通过简码创建的所有联系表单?请检查图像,谢谢。


更新: 这是我的代码,可以工作!
$args = array('post_type' => 'wpcf7_contact_form', 'posts_per_page' => -1);
$rs = array();
if( $data = get_posts($args)){
foreach($data as $key){
$rs[$key->ID] = $key->post_title;
}
}else{
$rs['0'] = esc_html__('No Contact Form found', 'text-domanin');
}
Run Code Online (Sandbox Code Playgroud)
下面是一个下拉列表:
<select name="field-name" id="field-id">
<option value="">--Select--</option><?php
$dbValue = get_option('field-name'); //example!
$posts = get_posts(array(
'post_type' => 'wpcf7_contact_form',
'numberposts' => -1
));
foreach ( $posts as $p ) {
echo '<option value="'.$p->ID.'"'.selected($p->ID,$dbValue,false).'>'.$p->post_title.' ('.$p->ID.')</option>';
} ?>
</select>
Run Code Online (Sandbox Code Playgroud)