简体   繁体   English

如何创建通过高级自定义字段(ACF)分类返回自定义帖子类型的查询?

[英]How to create a query that return custom post type by Advanced Custom Field(ACF) Taxonony?

you all!你们!

I have categories of Author我有作者类别

  • 1 - Freelancer 1 - 自由职业者
  • 2 - Contract 2 - 合同
  • 3 - Half-time 3 - 半场

I have categories of Books我有书籍类别

  • 1 - Novel 1 - 小说
  • 2 - Fiction 2 - 小说

I have a custom post type Author.我有一个自定义帖子类型作者。 Author has custom fields:作者有自定义字段:

  • Name: Text名称:文本
  • Type: Category类型:类别

I have a custom post type Book.我有一个自定义帖子类型书。 Book has custom fields:有自定义字段:

  • Title: Text标题:文本
  • Author: Taxonomy作者:分类学
  • Type: Category类型:类别
  • Pages: Number页数:数量

I need a query that return ALL BOOKs with Authors that have Contract ID = 1我需要一个查询,返回所有作者的合约 ID = 1 的书籍

And

I need a query that return ALL BOOKs with Type = Fiction我需要一个查询,返回所有类型 = Fiction 的书籍

Thanks!!!谢谢!!!

You should use meta_query to get the desired results:您应该使用 meta_query 来获得所需的结果:

I need a query that return ALL BOOKs with Authors that have Contract ID = 1我需要一个查询,返回所有作者的合约 ID = 1 的书籍

$freelance_books = get_posts(array(
    'numberposts'   => -1,
    'post_type'     => 'books',
    'meta_key'      => 'book_contract', // Adjust here with your field name
    'meta_value'    => 1
));

I need a query that return ALL BOOKs with Type = Fiction我需要一个查询,返回所有类型 = Fiction 的书籍

$fiction_books = get_posts(array(
    'numberposts'   => -1,
    'post_type'     => 'books',
    'meta_key'      => 'book_type', // Adjust here with your field name
    'meta_value'    => 2
));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 显示来自自定义帖子类型分类法的高级自定义字段(ACF)值-Wordpress - Display advanced custom field (ACF) value from custom post type taxonomy - wordpress 使用 ACF(高级自定义字段)自定义值动态创建链接 - Dinamically create a link using ACF (Advanced Custom Field) custom value 如何使用选择器高级自定义字段为自定义帖子类型指定查询? - How to specify a query for a custom post type using the selector advanced custom field? 如何通过 ACF 关系字段查询自定义帖子类型 (CPT)? - How do you query a custom post type (CPT) via an ACF relationship field? 如何在自定义帖子类型循环中获取ACF字段 - How To Get ACF Field in Custom Post Type Loop Wordpress:如何使用 ACF 和自定义帖子类型制作唯一字​​段 - Wordpress: How to make unique field with ACF and custom post type WordPress:自定义帖子类型查询未找到高级自定义字段meta_query - Wordpress: Custom Post Type query not finding advanced custom field meta_query 自定义字段(ACF)图像不仅限于它上传到的单个帖子,而且不显示在我创建的每种帖子类型上 - Custom field (ACF) image is not exclusive to the single post it's uploaded to and displays on every post type I create WordPress计数自定义帖子类型高级自定义字段 - WordPress count custom post type Advanced Custom Field 标题自定义帖子类型 ACF - Title custom post type ACF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM