Rest API work for me for this combination – domain.com/wp-json/wp/v2/custom-post, but my app read only standard wp/v2/posts.

How i can add custom post to standard WordPress category and REST API?

I add custom post to normal category, but still dont see custom post in REST API Posts.

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';
}

Read more here: WordPress Custom post to standard REST API Posts


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: