Hello
I am trying to:
load all my post titles of a specific custom post type into a select box of my contact form.
Currently, I'm using Contact Form 7
Here is the solution :
You need to create a custom shortcode in the contact form 7 for the select box. In order to create the custom shortcode for displaying title in select box, you can use the following custom shortcode.
Add this code to your function.php file.
I am trying to:
load all my post titles of a specific custom post type into a select box of my contact form.
Currently, I'm using Contact Form 7
Here is the solution :
You need to create a custom shortcode in the contact form 7 for the select box. In order to create the custom shortcode for displaying title in select box, you can use the following custom shortcode.
Add this code to your function.php file.
add_action(
'wpcf7_init'
,
'custom_views_post_title'
);
function
custom_views_post_title() {
wpcf7_add_shortcode(
'custom_views_post_title'
,
'custom_views_post_title_shortcode_handler'
);
}
function
custom_views_post_title_shortcode_handler(
$tag
) {
global
$post
;
$args
=
array
(
'post_type'
=>
'event'
);
$myposts
= get_posts(
$args
);
$output
=
'<select name="
eventname
" id="fleet" onchange="document.getElementById(\'fleet\').value=this.value;"><option></option>'
;
foreach
(
$myposts
as
$post
) : setup_postdata(
$post
);
$title
= get_the_title();
$output
.=
'<option value="'
.
$title
.
'">'
.
$title
.
' </option>'
;
endforeach
;
$output
.=
"</select>"
;
return
$output
;
}
and use the shortcode [custom_views_post_title] in contact form 7.
Now how to display in contact form 7 email :
Your code is :
$output
= '<select name=
"eventname"
>
So write
[
eventname
]
perfect, thanks you so much
ReplyDeletevery interesting post.this is my first time visit here.i found so mmany interesting stuff in your blog especially its discussion..thanks for the post! Search Bar Firefox 57 Quantum addon
ReplyDeleteExclusive information. Thanks for sharing.
ReplyDeletePopup builder Plugin
Hello, I read your blog occasionally, and I own a similar one, and I was just wondering if you get a lot of spam remarks? If so how do you stop it, any plugin or anything you can advise? I get so much lately it’s driving me insane, so any assistance is very much appreciated.
ReplyDeletepython training in chennai
python course in chennai
python training in bangalore
The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea.keep it up!!
ReplyDeleteandroid training in chennai
android online training in chennai
android training in bangalore
android training in hyderabad
android Training in coimbatore
android training
android online training
yeni perde modelleri
ReplyDeletesms onay
mobil ödeme bozdurma
NFTNASÄ°LALÄ°NÄ°R.COM
ankara evden eve nakliyat
Trafik sigortası
dedektör
web sitesi kurma
aşk kitapları
Smm panel
ReplyDeletesmm panel
iş ilanları
İnstagram takipçi satın al
hirdavatciburada.com
beyazesyateknikservisi.com.tr
SERVÄ°S
tiktok hile