Wordpress - 在帖子类型查询中按类别抓取项目
我在 Wordpress 中设置了自定义帖子类型。 这是一个客户可以上传 PDF 格式文件的部分。 这些文件分为两类——“可下载表格”和“菜单”; 该类别的自定义字段名称是“document_category”
我正在尝试运行查询并仅在页面上显示“可下载表单”。 这是我通常使用的代码 --- 我希望有人可以帮助我添加使其工作所需的代码?
<?php
$args = array('post_type' => 'prep_forms', 'posts_per_page' => -1);
// The Query
$the_query = new WP_Query( $args );
// The Loop
$i = 0;
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<li><a href="<?php echo get_field('document_pdf_file'); ?>"><?php the_title(); ?></a></li>
<?php
$i++;
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
谢谢。
I have setup a custom post type in Wordpress. It is a section where the client can upload documents in PDF format. The documents are divided into two categories - 'Downloadable Forms' and 'Menu' ; the Custom Field name for the category is 'document_category'
I am trying to run a query and only display the 'Downloadable Forms' on a page. Here is the code I normally use --- I'm hoping someone can help me add what I need to make it work?
<?php
$args = array('post_type' => 'prep_forms', 'posts_per_page' => -1);
// The Query
$the_query = new WP_Query( $args );
// The Loop
$i = 0;
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<li><a href="<?php echo get_field('document_pdf_file'); ?>"><?php the_title(); ?></a></li>
<?php
$i++;
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
评论(3)
我使用了 Advanced Custom Fields 插件的
get_fields($post_id = false)
函数,它返回所有帖子的自定义字段的数组,然后过滤它以满足您的需要。希望我有帮助
I've used the
get_fields($post_id = false)
function of the Advanced Custom Fields plugin that returns an array of all the posts' custom fields and then filtered it to match your needs.Hope i've helped
好吧,你可以使用 is_category(); 内部循环并只显示那些帖子,就像这样(使用相同的代码):
更好的是:http://codex .wordpress.org/Function_Reference/is_category
希望对您有所帮助。
Well, you can use the is_category(); inside loop and only display those posts, like so (using your same code):
Better yet: http://codex.wordpress.org/Function_Reference/is_category
Hope that helps.
为什么不简单点,设置一个基于自定义字段数据的查询呢?
这样,任何带有自定义字段键 display 和自定义字段值 true 的帖子都将显示在您的查询中。
Why dont you make it simpler and set a query based on custom field data?
That way any post with custom field key display and custom field value true will be shown on your query.