How to load Nav items data after fetching WordPress Menus

Hi there,

I’ve followed this lovely tutorial on how to fetch the WordPress Menus in Frontity.

I’m returning a menu called ‘featured-post’ which has one item: a post with a id of 70, it’s title, URL, etc. No problems returning the menu JSON or anything.

However, I also need to get that posts image and excerpt, which is not found in the menu JSON. That post is also not found in state.source.posts - so I’m wondering how exactly I can fetch that post’s data, in the most efficient way possible?

Thanks in advance!

You would need to do a 2 step process where you fetch the post as well.
I believe if you use _embed, as a param when fetching, frontity will automatically populate the state also with the featured image.

As for the most efficient way possible, I would say that is the fetch from wp-source. @frontity/wp-source - API Reference
You have the link already so that should not be an issue

Good luck. Hopefully this helps.

1 Like

Thanks so much, very helpful!

1 Like

I ended up calling the following function in theme actions > beforeSSR

await actions.source.fetch(/menu/featured-post/)

which preloads my featured post. However, the load time is incredibly slow. The featured post takes about 4-5 seconds to load and the whole page jumps. I’m hoping there’s some way to resolve this without cacheing, as the featured post may be changing every day and it’s key it updates quickly for our website. Is there any way to grab the featured post at a similar time to all the rest of the initial posts?

Wordpress API is notoriously slow by default, so it will require lots of optimizations. As for the best way to handle it? Make a good loading state with a loading skeleton on something like this so the page doesnt jump.