I have developed an app using ionic 2 that revolves around quotes. My goal is to manage these quotes (along with authors, categories, etc) using Wordpress and its REST API. Initially, I utilized normal posts for this purpose, but now I am exploring custom post types as they offer more control and organization in the backend. This led me to create one CPT for quotes
and another for authors
, establishing a relationship between them.
For example:
wp-json/wp/v2/quotes
[
{
id: 79,
x_metadata: {
custom_post_type_onomies_relationship: "77",
quote: "Be yourself; everyone else is already taken"
}
}
]
wp-json/wp/v2/authors
[
{
id: 77,
title: {
rendered: "Oscar Wilde"
},
x_metadata: {
bio: "https://wikipedia.org/wiki/Oscar_Wilde"
}
}
]
In the above example, you can see that the relation is defined by
custom_post_type_onomies_relationship
, but I am unsure of how to properly merge this data within the app (where Angular 2/Typescript is used).
The only solution that comes to mind is to loop through the quotes, then for each quote, loop through authors to check their IDs, and finally add the author's data into the quotes array. Is this approach acceptable or is there a more efficient method available?
Thank you in advance and please forgive any imperfections in my English.