I have a CPT called Icons
I tested the API with this link and it is working very well
link https://wp.local/wp-json/wp/v2/icons?slug=icon_slug
output
[
{
"id": 461,
"date": "2020-01-14T11:16:59",
"date_gmt": "2020-01-14T11:16:59",
"guid": {
"rendered": "http://wp-local/?post_type=icons&p=461"
},
"modified": "2020-01-14T13:00:08",
"modified_gmt": "2020-01-14T13:00:08",
"slug": "icon_slug",
"status": "publish",
"type": "icons",
"link": "https://wp-local/icons/icon_slug/",
"title": {
"rendered": "icon_slug"
},
"template": "",
"acf": {
"main_page_color": "",
"icon_code": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"34\" height=\"34\" viewBox=\"0 0 34 34\">\r\n <path fill=\"var(--color)\"\r\n d=\"M5.047 20.055a2.988 2.988 0 1 1 0 5.976 2.988 2.988 0 0 1 0-5.976zM17 0a2.988 2.988 0 1 1 0 5.977A2.988 2.988 0 0 1 17 0zm11.953 20.055a2.988 2.988 0 1 1 0 5.976 2.988 2.988 0 0 1 0-5.976zm0 5.976c2.746 0 5.047 2.234 5.047 4.98V34H23.973v-2.988c0-.664.136-1.296.372-1.875l-4.241-2.828c-.775.676-1.622 1.35-2.451 2.068l-.653.566s-2.348-1.995-3.088-2.645l-4.257 2.839c.236.58.372 1.21.372 1.875V34H0v-2.988c0-2.747 2.3-4.98 5.047-4.98 1.365 0 2.603.553 3.504 1.446l3.904-2.603c-.85-.96-1.394-1.945-1.394-3.134 0-2.063 1.524-3.679 3.468-3.679.577 0 1.064.137 1.475.35v-4.334H12.02v-3.121A4.986 4.986 0 0 1 17 5.977a4.986 4.986 0 0 1 4.98 4.98v3.12h-3.984v4.334c.41-.212.898-.349 1.475-.349 1.944 0 3.468 1.616 3.468 3.68 0 1.188-.56 2.193-1.385 3.14l3.895 2.596a4.963 4.963 0 0 1 3.504-1.447z\"/>\r\n </svg>"
},
"_links": {
"self": [
{
"href": "https://wp-local/wp-json/wp/v2/icons/461"
}
],
"collection": [
{
"href": "https://wp-local/wp-json/wp/v2/icons"
}
],
"about": [
{
"href": "https://wp-local/wp-json/wp/v2/types/icons"
}
],
"wp:attachment": [
{
"href": "https://wp-local/wp-json/wp/v2/media?parent=461"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
}
]
in index.js I added this code
state: {
source: {
postTypes: [
{
type: 'icons',
endpoint: 'icons',
},
],
},
},
after that I tried to use this CPT as following
actions.source.fetch(`/icons/icon_slug/`);
const icon = state.source.get(`/icons/icon_slug/`);
console.log(icon);
if (icon.isReady) {
console.log(state.source[icon.type][icon.id]);
}
But in the console I always get this
{isReady: false, isFetching: true}
I really help here as I can’t see where is the problem
Thanks in advance