The team is now working on the WordPress Interactivity API. This unblocks the same UX Frontity framework enabled but directly in WordPress Core, fully compatible with the new Site Editor.
Iām having trouble understanding how to get data from posts, configured in an ACF Post Object field. Itās possible to configure the Post Object field to return itās value as post IDs or Post Objects. But the Post Object doesnāt contain all needed information, like the featured image.
I want to build a slider for my front-page, the slides should contain the link to the configured post and show the title and featured image. The title is passed with ACF, the link Iām able to generate using post_name, but the featured-image isnāt available.
So I need to fetch the whole post, I guess. But I canāt figure out how to retrieve more data, when Iām working in a component.
The other way would be to get the ID of the post that you want and fetch it separately. Let me know how you get on with the first solution and if that fails then we can look at doing this.
dominique6
Hi @mburridge, for this specific case I guess it would be sufficient to just add the featured-image to the output of ACF. Thanks for the link. I think I can solve this problem that way.
But still, I am wondering how to retrieve information of a specific post/term in a component. Because there are so much more fragments of data which youād want to use, than that ACF is handing over by default. I donāt think it should be that way that youād need to manually add this data to ACF, while the data is available if youād be able to retrieve the whole post.
Think about data like:
featured image
excerpt (ACF only outputs it if youāve manually set it)
rendered content (ACF only outputs unrendered post-content)
post template
attached ACF fields
dominique7
I am bumping my way through this, and got a bit further now.
Iāve added this filter to my WordPress installation:
This results in having the ID of the featured-image in the REST output. And I can use this in my slider.js file. However, the featured-image is not being rendered on the front-page. When I visit āBlogsā and return to the front-page, it is being rendered. So it looks like it isnāt fetched when visiting the front-page.
The ACF options are not the problem, otherwise the slides would not be visible. Itās the attachments that arenāt available to Frontity at the moment of visiting the front-page.
When visiting the blogs page, apparently they are being fetched, but not when visiting the front page. The slider will only show images that are being loaded on the blogs page, so if the image is not in one of the articles on the blogs page, they wonāt show up in the front-page slider either.
dominique11
@mburridge
Iām very sorry for being so rude, but do you have any more ideas about whatās going on here and how to solve it?
1 Like
mburridge12
Hi @dominique
Sorry for the failure to communicate, Iāve cloned your repo locally and am working on trying to find a solution. Iāll let you know when I have anything to share.
1 Like
SantosGuillamot13
Not sure if I understood the case 100%, but if you have the ids or the slugs of the posts you want, wouldnāt be better to use something like fetch to populate the state with all the info about each post? This way, you would have any info like the title or the featured image in state.source.post[id].
dominique14
Hi @SantosGuillamot,
I looked at the documentation of fetch before and tried to use it, but I couldnāt get it working the way I needed to.
After reading your post I tried one more time and low and behold: it worked! The posts are now being fetched and the images are being shown. Iām not sure what Iām doing different then before, but of course there must be a difference.
Thanks for encouraging me to try it once more!
For future reference for others, hereās the code for my slider: