Skip Navigation

[Resolved] How to read theToolset custom fields in REST API (toolset-meta) with Javascript

This support ticket is created 3 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by SigfusB1367 3 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#2010265

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>
)
}

#2010385

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

#2010459

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>
)
}

#2010465

Dear Waqur
I got it! I forgot the "recept" You made my day!

<h1>Portioner: {recept.data["toolset-meta"].recept.portions.raw}</h1>

#2010467

You made my day (as always)
My issue is resolved now. Thank you!