Используйте get_the_ID(), чтобы получить идентификатор вашего сообщения в цикле и использовать его для получения метаданных.
function my_recent_posts_shortcode($atts){
$q = new WP_Query(
array('orderby' => 'date', 'posts_per_page' => '4', 'post_type' => 'events')
);
$list = '<ul class="recent-posts">';
while($q->have_posts()) : $q->the_post();
//get the ID of your post in the loop
$id = get_the_ID();
//now get your registration link
$link = get_post_meta($id, 'registration_link', true);
$list .= '<li>' . get_the_date() . '<a href="' . $link . '">Register</a><a href="' . get_permalink() . '">' . get_the_title() . '</a>' . '<br />' . get_the_excerpt() . '</ul>';
endwhile;
wp_reset_query();
return $list;
}
add_shortcode('recent-posts', 'my_recent_posts_shortcode');
примечание: staff_photo - мой пользовательский ключ поля. –
Что значит, что вам это нужно в пользовательском запросе? – WebNovice
Я имею в виду запрос. Я буду запрашивать пользовательские сообщения. вот так: http://web-design-weekly.com/blog/snippets/recent-post-shortcode/ –