我们已经创建了自定义贴子“产品”和自定义分类“管理供应商”。在管理供应商部分,添加自定义复选框“特色供应商”,以便使用ACF对特色产品进行分组,并分配给管理供应商。现在,当我们添加供应商时,有一个标记特色供应商的选项。问题是如何生成循环,以便在主页上显示选定的供应商。
如何在前端主页上显示选中的复选框供应商?
1 个回复
SO网友:Andy Macaulay-Brook
ACF是一个第三方插件,我不知道它给了你什么功能,你可以使用。
不过,一般来说,您可以使用特定的自定义字段和值为帖子创建查询。
$args = array(
\'meta_key\' => \'featured\', // must match the key that ACF has used
\'meta_value\' => true, // must match the value that ACF has used
\'post_type\' => \'product\' // must match your post type
);
$the_query = new WP_Query( $args );
然后像正常情况一样运行二次回路:if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
// output html for each post here
}
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}
根据您的需要,您可以将其放入front-page.php
模板,钩住它the_content
或者把它变成一个短代码。