Display post taxonomy REST API
-
Playing around with VUEJS and the WordPress Rest API I can display my custom posttype on the page. The custom posttype also has a custom taxonomy, but I can’t seem to find a way to display that.
I did read some stuff about adding /?_embed to the endpoint url and ‘show_in_rest => true’ to add support to the API and if I log the result I do get _embedded as an array.
Only the name of the taxonomy isn’t there.Am I missing some steps to add the taxonomy of the custom post in the API result?
DOM snippet
<div id="workfeed" class="work" style="margin-top: 100px;"> <div v-for="(item,index) in work" class="row work__item" :data-index="index"> <div class="col work__item-image"> <img :src="item._embedded['wp:featuredmedia'][0].source_url" /> </div> <div class="col work__item-content"> <h3>{{ item.title.rendered }}</h3> {{ item.content.rendered }} {{ item._embedded['wp:term'].rendered }} </div> </div> </div>
Snippet custom posttype
$args = array( 'labels' => $labels, 'description' => 'All projects', 'public' => true, 'menu_icon' => 'dashicons-layout', 'supports' => array('title', 'editor', 'thumbnail'), 'has_archive' => true, 'show_in_rest' => true, 'rest_base' => 'work-api', 'rest_controller_class' => 'WP_REST_Posts_Controller' ); register_post_type('work', $args); } add_action('init', 'cptWork', 0);
Snippet custom taxonomy
register_taxonomy('types',array('work'), array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'type' ), 'show_in_rest' => true, 'rest_base' => 'work-api', 'rest_controller_class' => 'WP_REST_Terms_Controller' )); } add_action( 'init', 'taxWork', 0 );
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Display post taxonomy REST API’ is closed to new replies.