如果
<?php the_title(); ?> = ' . get_the_title() . '
<?php the_permalink(); ?> = ' . get_permalink() . '
然后,
<?php echo get_post_meta($post->ID, 'staff_photo', true); ?> = ?
我在自定义查询中需要它。
答案 0 :(得分:3)
使用 get_the_ID()在循环中获取帖子的ID,并使用该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');
答案 1 :(得分:0)
尝试print_r($ customFields)或print_r($ post),这些数组可探测地拥有U所需的数据。 不要忘记将它们声明为全球第一。