Display meta_key
-
as from the title I’m trying to get my meta keys to insert into my contact form 7 in the form of <select>
` // Dynamic Select for Contact Form 7
function dynamic_select_for_custom_posts($choices, $args=array()) {// Here we grab the posts using the arguments originated from the shortcode
$get_custom_posts = get_posts($args);// If we have posts, proceed
if ($get_custom_posts) {// Foreach found custom post, we build the option using the [key] => [value] fashion
foreach ($get_custom_posts as $custom_post) {
$choices[$custom_post->post_title] = $custom_post->post_title;
}// If we don’t have posts, halt! Lets use a generic not found option
} else {// Just a generic option to inform nothing was found
$choices[‘No posts found’] = ‘No posts found’;}
return $choices;
}
// Lets add a suggestive name to our filter (we will use it on the shortcode)
add_filter(‘conjure-posts-dynamically’, ‘dynamic_select_for_custom_posts’, 10, 2);`after:
[dynamicselect* desired-game class:browser-default class:custom-select include_blank "conjure-posts-dynamically post_type=suite posts_per_page=-1 meta_key=metakey_AMC_tavoli "]
obviously my meta key to recover is the following as you can read:metakey_AMC_tavoli
I just can’t get the function out to get get_post_meta
into function:
$choices[$custom_post->post_title] = $custom_post->post_title;
I don’t want the post titles, but the meta_value of the meta key:metakey_AMC_tavoli
my custom post type: suite
my meta_key: metakey_AMC_tavoli
i can do this?
- The topic ‘Display meta_key’ is closed to new replies.