Hi there
I'm trying to access the custom fields in a REST API by Javascript.
See for example:
hidden link
I have not problem to read the standard WordPress fields (Title, image, id) but I cant figure out how to get the toolset-meta fields.
Including "toolset-meta" in the script does not work.
Best regards
Sigfús
if (recept.data) {
content = (
<div>
<div>
<h1 className="m-3 font-bold text-2xl">{recept.data.title.rendered}</h1>
</div>
<div>
<img src={recept.data.uagb_featured_image_src.medium_large[0]} alt=""></img>
</div>
<div>
<h1>Recept id: {recept.data.id}</h1>
</div>
<div>
<h1>Portioner: {recept.data.toolset-meta.recept.portions.raw}</h1>
</div>
</div>
)
}
Hi,
Thank you for contacting us and I'd be happy to assist.
Variables cannot contain - as that is read as the subtract operator.
You'll need to change the ".toolset-meta" part to "['toolset-meta']", for example:
{recept.data.toolset-meta.recept.portions.raw}
Will become:
{recept.data['toolset-meta'].recept.portions.raw}
regards,
Waqar
Hi Waqar
I did that, but it still does not work. If I include"raw" at the end my app does not compile. If I exclude it I don't get any error messages or warnings but I dont get any value returned.
This is how my code looks now:
if (recept.data) {
content = (
<div>
<div>
<h1 className="m-3 font-bold text-2xl">{recept.data.title.rendered}</h1>
</div>
<div>
<img src={recept.data.uagb_featured_image_src.medium_large[0]} alt=""></img>
</div>
<div>
<h1>Recept id: {recept.data.id}</h1>
</div>
<div>
<h1>Portioner: {recept.data['toolset-meta'].portions}</h1>
</div>
</div>
)
}
Dear Waqur
I got it! I forgot the "recept" You made my day!
<h1>Portioner: {recept.data["toolset-meta"].recept.portions.raw}</h1>
You made my day (as always)
My issue is resolved now. Thank you!