【发布时间】:2020-02-06 22:27:27
【问题描述】:
我在我的 Wordpress 模板中使用了这段代码:
<?php
$args = array( 'numberposts' => '12', 'post_type' => 'training', 'post_status' => 'publish' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ) {
echo '<div class="col-xs-12 col-md-4"><article><div class="kartel"><a href="' . get_permalink($recent["ID"]) . '">';
if ( has_post_thumbnail( $recent["ID"]) ) {
echo get_the_post_thumbnail($recent["ID"],'medium');
}
echo '</a></div><a href="' . get_permalink($recent["ID"]) . '"><h3>' . $recent["post_title"].'</h3></a> ';
echo '<em>Doelgroep //</em>
<p>One-liner/super korte omschrijving</p>';
echo '<a href="' . get_permalink($recent["ID"]) . '">Tell me more</a> ';
echo '</article></div>';
}
wp_reset_query();
?>
问题是我现在想添加一个自定义字段(比如说“custom_field”),它在网格的缩略图下方显示自定义摘录。我可以获取常用字段(摘录、标题等),但不能获取自定义字段。例如 the_field('custom_field');不工作..
有什么想法/建议吗?
希望收到你们的来信!
过滤
【问题讨论】:
-
你没有用 wp 查询循环它,所以你必须告诉 get_field() 或 the_field() 函数你想从哪个页面 id 显示。试试
the_field( 'custom_field', $recent["ID"] ); -
太棒了,这很有效,也许不是最好的方法,但至少是最快的!谢谢
标签: wordpress advanced-custom-fields