WordPress的:通过帖子与自定义字段循环
问题描述:
我循环通过职位和category_name =新闻,我怎样才能显示每个职位的自定义字段?先谢谢你。WordPress的:通过帖子与自定义字段循环
<?php $preNewsPosts = new WP_Query();
$preNewsPosts->query('posts_per_page=3&category_name=news');
while($preNewsPosts->have_posts()): $preNewsPosts->the_post();
?>
<a href="<?php the_permalink(); ?>" class="atitle" ><?php the_post_thumbnail('thumbnail'); ?><?php the_title(); ?></a>
<?php
the_excerpt();
?>
<hr style="width: 95%; border: 1px solid #e6e6e6; " />
<?php
endwhile;
?>
答
这应该工作,只需将while
循环中。请确保您更改custom_field
您的自定义字段的名称
echo get_post_meta($preNewsPosts->post->ID, 'custom_field', true);
我会尝试这一个感谢 – s4m 2013-04-09 01:51:12
你可能要加上'$全球后,'以及 – doublesharp 2013-04-09 03:05:47
,因为你正在使用'wp_query'可以/应该使用'$ preNewsPosts-> post-> ID'来获得id ..不需要全局$ post – 2013-04-09 03:43:37