shortcode including the ID variable
-
Hi,
I am using this plugin together with a shortcode.
I created a shortcode to get a specific field. But I need to include the ID of the current post.
However it doesn’t seem to get the id.
See my shortcode exmaple below
function user_details() {
add_shortcode(‘au_display_user’, ‘func_user_details’);
}
add_action(‘init’, ‘user_details’);
function func_user_details($atts){
extract(shortcode_atts(array(
‘p_id’ => ”,
), $atts));
$user_names = get_post_meta($p_id, ‘agent’, true);
//print_r($user_names);
$return_string = ”;
$args = array(‘post_type’ => ‘agent’, ‘post__in’ => $user_names, “posts_per_page” => 1);
$q = get_posts($args);
foreach ($q as $p) :
$a = $p->ID;
$email = get_post_meta($a, ’email’, true);
$return_string .= $email;
endforeach;
return $return_string;
}I am using the following shortcode [dynamictext userdetails “au_display_user p_id=’ID'”]
It displays an email address but not from the correct post id.
Thanks in advance!
- The topic ‘shortcode including the ID variable’ is closed to new replies.