Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何通过术语id WordPress获得定制帖子的有限或特定字段?_Php_Wordpress_Post_Custom Post Type - Fatal编程技术网

Php 如何通过术语id WordPress获得定制帖子的有限或特定字段?

Php 如何通过术语id WordPress获得定制帖子的有限或特定字段?,php,wordpress,post,custom-post-type,Php,Wordpress,Post,Custom Post Type,我使用了以下查询: $args = array( 'post_type' => 'blogs', 'tax_query' => array( array( 'taxonomy' => 'blog', 'field' => 'term_id', 'terms' => $backendEngineering->term_id ) ) ); $responseData = new WP_Query( $args ); e

我使用了以下查询:

$args = array(
'post_type' => 'blogs',
'tax_query' => array(
    array(
    'taxonomy' => 'blog',
    'field' => 'term_id',
    'terms' => $backendEngineering->term_id
     )
  )
);
$responseData = new WP_Query( $args );
echo '<br/>';
print_r($responseData);
echo '<br/>';
$args=array(
“帖子类型”=>“博客”,
“tax_query”=>数组(
排列(
“分类法”=>“博客”,
'field'=>'term_id',
“术语”=>$backendEngineering->term\u id
)
)
);
$responseData=新的WP_查询($args);
回声“
”; 打印(应答数据); 回声“
”;
很好用。但我的要求是只获取
post name
post ID

这可能吗?如果是,那么我们怎么做呢?

您可以使用返回字段获取

更新的参数如下

$args = array(
'post_type' => 'blogs',
 'fields'=>'ids',
'tax_query' => array(
array(
'taxonomy' => 'blog',
'field' => 'term_id',
'terms' => $backendEngineering->term_id
 )
 )
);

但是这里没有返回标题的选项。希望它能对您有所帮助。

只需编写一个函数来循环查询结果并获取所需的数据

function echo_post_title_and_id(){
   $args = array(
   'post_type' => 'blogs',
   'tax_query' => array(
       array(
       'taxonomy' => 'blog',
       'field' => 'term_id',
       'terms' => $backendEngineering->term_id
        )
     )
   );
   $responseData = new WP_Query( $args );

      if ( $responseData->have_posts() ) {
              while ( $$responseData->have_posts() ) {
                     $responseData->the_post();
                      echo get_the_title();
                      echo get_the_id();
             }
      }else {
           echo 'no posts found';
      }
       wp_reset_postdata();
}

不,这是不可能直接实现的-fields参数仅允许您请求id only、id only和parent id,或-everything。嘿,你的回答有道理,谢谢:)