искал способ получить избранное изображение, но, похоже, он не выводит данные, используя {{post._embedded ['wp: featuredmedia']. Link}}, хотя был использован _embed.Интересно, есть ли что-то не так с моим кодом и кто-то может помочь мне?
export class WordPressRestapiService {
baseRestApiUrl: string = this.appConfig.Shop_URL + '/wp-json/wp/v2/';
constructor(private httpClient: HttpClient, public appConfig: AppConfig) { }
getRecentPosts(categoryId: number, page: number = 1): Observable<Post[]> {
// Get posts by a category if a category id is passed
let category_url = categoryId ? ("&categories=" + categoryId) : "";
return this.httpClient.get(this.baseRestApiUrl + "posts?_embed&page=" + page + category_url ).pipe(
map((posts: Post[]) => {
return posts.map((post) => new Post(post));
}),
catchError(error => {
return Observable.throw('Something went wrong ;)');
})
);
}
getPost(postId: number): Observable<Post> {
return this.httpClient.get(this.baseRestApiUrl + "posts/" + postId + "?_embed").pipe(
map(post => {
return new Post(post);
}),
catchError(error => {
return Observable.throw('Something went wrong ;)');
})
);
}
}