Android Wordpress自定义文章到标准RESTAPI文章
RESTAPI在这种组合中对我有用-domain.com/wp json/wp/v2/custom post,但我的应用程序只读标准wp/v2/posts 如何将自定义帖子添加到标准Wordpress类别和RESTAPI 我将自定义帖子添加到普通类别,但在RESTAPI帖子中仍然看不到自定义帖子Android Wordpress自定义文章到标准RESTAPI文章,android,json,wordpress,rest,Android,Json,Wordpress,Rest,RESTAPI在这种组合中对我有用-domain.com/wp json/wp/v2/custom post,但我的应用程序只读标准wp/v2/posts 如何将自定义帖子添加到标准Wordpress类别和RESTAPI 我将自定义帖子添加到普通类别,但在RESTAPI帖子中仍然看不到自定义帖子 add_action( 'init', 'myfuncxx'); function myfuncxx() { register_taxonomy_for_object_type( 'catego
add_action( 'init', 'myfuncxx'); function myfuncxx() {
register_taxonomy_for_object_type( 'category', 'review' );
}
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if( is_category() ) {
$post_type = get_query_var('review');
if($post_type)
$post_type = $post_type;
else
$post_type = array('nav_menu_item', 'post', 'review'); // don't forget nav_menu_item to allow menus to work!
$query->set('post_type',$post_type);
return $query;
}
}
add_action( 'init', 'add_myCustomPostType_endpoint');
function add_myCustomPostType_endpoint(){
global $wp_post_types;
$wp_post_types['review']->show_in_rest = true;
$wp_post_types['review']->rest_base = 'posts';
$wp_post_types['review']->rest_controller_class = 'WP_REST_Posts_Controller';
}
您可以在注册帖子类型时添加
show_in_rest
…我有这个$wp_post_types['review']->show_in_rest=true$wp_post_类型['review']->rest_base='posts'$wp_post_type['review']->rest_controller_class='wp_rest_Posts_controller'代码>我在REST API中看到了自定义帖子(wp json/wp/v2/review)-但我想将此帖子添加到标准API链接(帖子,无评论)您可以在注册帖子类型时添加show_in_REST
…我有这个$wp_post_types['review']->show_in_REST=true$wp_post_类型['review']->rest_base='posts'$wp_post_type['review']->rest_controller_class='wp_rest_Posts_controller'代码>我在RESTAPI中看到了自定义帖子(wp-json/wp/v2/review)-但我想将此帖子添加到标准API链接(帖子,无评论)