Can't get data on pages or post unless the homepage is loaded first

Hey guys,

My problem is simple, still did not find any solutions…

I would like to show some post on other pages than the homepage. It works until the homepage is loaded first. If I refresch that specific page, the data of all the post are not loaded.

I am using:
const data = state.source.get("/");
I also tried:
state.source.data
but nothing…

Do you guys have a solution?

Hi,

Can you be more specific about what your are trying to do ? What is the specific page ? An archive page ? Can you provide some code or better a codesandbox ?

From what I understand now it look like you need a custom handler (scroll down to custom handler)

Hey 1600tc,

Thanks for your response. I am trying to show some of the blog posts on some custom pages I have created on my Frontity website. Similar thing as I have done already on the homepage. Imaging it like creating multible homepage but on custom pages (non-wp pages).

I can share my github link to the project I have created if that helps.

Regards,
Kris

I’m no expert but from what I understood state.source.get() is there to get data , usually with actions.source.fetch.

But you are using it in the wrong way, you don’t need to manually fetch posts , as Frontity already do this for you in state.source.post, it will fetch the first 10 posts (can be changed, I use 20 in my last blog)

Instead just do const mySexyPosts = state.source.post,
this will return an array of object with your posts
and should avoid your issue.
State.source.get is really handy when you need to query some specific data but that’s also the reason why you can’t access your posts directly, state.source.get means in your case “return homepage data”

but fetching homepage can be useful to preload data

  useEffect(() => {
    actions.source.fetch("/");
    List.preload();
  }, []);

. In state.source there is almost every time what you need

check out those links
wp-source

frontity state

let me know if thats helps

Thank you for your response.
It did actually work! After calling actions.source.fetch("/") in useEffect it had loaded it perfectly.

glad it work :+1: