通过术语ID自定义查询
-
-
这是jdm2112所指的食典:[使用自定义选择查询显示帖子](http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query).他击败了我...Here is the Codex jdm2112 is referring to: [Displaying Posts Using a Custom Select Query](http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query). He beat me to it...
- 1
- 2014-06-20
- eyoung100
-
1 个回答
- 投票数
-
- 2014-06-20
您是否尝试过使用WP_Query类?您可能会发现,使用内置工具来进行此操作比从头开始进行自定义查询要容易得多.类似于以下内容的内容应该适合您:
<?php $args = array( 'post_type' => 'recipe_cpt', 'tax_query' => array( array( 'taxonomy' => 'recipe_tx', 'field' => 'term_id', 'terms' => 37 ) ) ); $query = new WP_Query( $args ); ?>
编辑:请注意,
tax_query
是根据设计的数组数组.许多税收查询问题是缺少此详细信息的结果.编辑:更正了上面的
field
值错字,将'id'替换为'term_id'.Have you tried using the WP_Query class? You might find it's easier to use the built-in tools for this instead of a custom query from scratch. Something similar to the following should work for you:
<?php $args = array( 'post_type' => 'recipe_cpt', 'tax_query' => array( array( 'taxonomy' => 'recipe_tx', 'field' => 'term_id', 'terms' => 37 ) ) ); $query = new WP_Query( $args ); ?>
EDIT: note the
tax_query
is an array of arrays by design. Many tax query problems are a result of missing this detail.EDIT: corrected
field
value typo above, replacing 'id' with 'term_id'.-
在这种情况下,如何查找带有LIKE子句的帖子?how i can find posts with LIKE clause int this case ?
- 0
- 2014-06-20
- Azeem Hassni
-
注意,"field"的可能值为"term_id","name"," slug"或"term_taxonomy_id".参见https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_ParametersNote that the possible values for `field` are `term_id`, `name`, `slug` or `term_taxonomy_id`. See https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
- 2
- 2017-11-22
- Marian
我想使用自定义查询来检索自定义帖子. 我的分类法是recipe_tx, 条款 (牛肉),(鸡肉)等.
我尝试使用
但没有运气.
有人可以帮助我如何通过term_id获得wp帖子.
如果牛肉id是37,那么我想检索所有帖子 与
term_id = 37
谢谢