How get info page by id?

I have ACF Field (Post Object) and it returns the id of the page, how can I get information about the page from component?)

I already received the page id, and now I need to get information about the page by this id.

Hi @prainua

Try this:

const pageinfo = state.source["page"][id]

Hope this helps.

returns undefined

@prainua where do you want to fetch the page component? Is it in React (like inside useEffect) or in a handler?

It’s a shame that the Post Object of ACF doesn’t include the link. I hope they can fix that in the future.

Basically something like this:

const SomePost = ({ state, actions }) => {
  const postData = state.source.get(state.router.link);
  const postItem = state.source.post[data.id];
  const extraPostLink = `/${post.acf.extra_post.slug}`;
  const extraPostData = state.source.get(extraPostLink);

  React.useEffect(() => {
    actions.source.fetch(extraPostLink);
  }, []);

  return (
    <>
      <PostStuff />
      {extraPostData.isReady && <ExtraPostStuff />}
    </>
  );
};

In this case, extraPost will only be present on client-side rendering, so it’s important that you check if it’s ready with .isReady. If extraPost belongs to a different custom post type, you may have to rebuild the link with that:

const extraPostLink = `/name-of-cpt/${post.acf.extra_post.slug}`;

If this is not clear enough let us know :slight_smile:

2 Likes

Thank you

this code helped me)
https://github.com/alexadark/frontity-starter-project/blob/master/packages/frontity-starter-theme/src/handlers/index.js

1 Like