用于分类法的WordPress自定义端点

时间:2018-08-21 19:19:01

标签: wordpress wordpress-theming wordpress-rest-api endpoints

我正在尝试创建一个自定义端点以获取分类法类别(ait-item),我也获得了所有数据,除了图像我找不到标题图像而且我不知道如何找到它或者是否有简单的功能可以做到这一点?

add_action( 'rest_api_init', function () {
register_rest_route( 'inovola/v1', '/categories', array(
 'methods' => 'GET',
 'callback' => 'emad_rest_test'
 ) );
} );

function emad_rest_test() {

$taxonomies = array( 
'ait-items'
);
$args = array(
'orderby'           => 'name', 
'order'             => 'ASC',
'hide_empty'        => false, 
'exclude'           => array(), 
'exclude_tree'      => array(), 
'include'           => array(),
'number'            => '', 
'fields'            => 'all', 
'slug'              => '',
'parent'            => '',
'hierarchical'      => true, 
'child_of'          => 0,
'childless'         => false,
'get'               => '', 
'name__like'        => '',
'description__like' => '',
'pad_counts'        => false, 
'offset'            => '', 
'search'            => '', 
'cache_domain'      => 'core'
 );

  $siteurl = home_url('/');


    $i = 0 ;
    $taxonomy = 'ait-items';
    $terms = get_terms($taxonomies, $args);
    $count = count($terms);
    if ( $count > 0 ){
 foreach ( $terms as $term ) {
 $id = $term->term_id;
 $image_url = get_category_link($term->term_id);
 $emadbishay[$i]['termlinks']=get_category_link($term->term_id);
 $emadbishay[$i]['term_id']= $term->term_id;
 $emadbishay[$i]['slug']= $term->slug;
 $emadbishay[$i]['name']= $term->name;
 $emadbishay[$i]['image'] = $image_url ;
 $emadbishay[$i]['taxonomy']= $term->taxonomy;
 $emadbishay[$i]['term_taxonomy_id']=$term->term_taxonomy_id ;
       $emadbishay[$i]['filter']= $term->filter ;
      $i++;
      }

   }

     return $emadbishay ;

   }

谢谢

0 个答案:

没有答案