2013-04-09 122 views
0

我循環通過職位和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; 
?> 

回答

1

這應該工作,只需將while循環中。請確保您更改custom_field您的自定義字段的名稱

echo get_post_meta($preNewsPosts->post->ID, 'custom_field', true); 
+0

我會嘗試這一個感謝 – s4m 2013-04-09 01:51:12

+0

你可能要加上'$全球后,'以及 – doublesharp 2013-04-09 03:05:47

+0

,因爲你正在使用'wp_query'可以/應該使用'$ preNewsPosts-> post-> ID'來獲得id ..不需要全局$ post – 2013-04-09 03:43:37

相關問題