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.
to just see the data BUT the problem iām having is that the handler iām making isnāt added to the frontity.libraries.source and I donāt know why.
I just updated it and made it public. Any help would be greatly appreciated, thanks!
mburridge2
Hi @brian.tucker
Welcome to the Frontity community.
You may need to use libraries.source.api.get to fetch the data from a specific endpoint such as https://gatorworksfron.wpengine.com/wp-json/acf/v3/options/options.
You will then also need to add the fetched data into the state using libraries.source.populate, as libraries.source.api.get doesnāt automatically populate the state in the way that actions.source.fetch does.
brian.tucker3
Would i be attempting to use that in the beforeSSR? I was able to view the acfOptionsHandler in frontity.libaries.source now but the data for the options is not be fetched. I tried using ālibraries.source.api.getā and then populating, but i found no success.
I followed your instructions on how to add the Wordpress menus and got a better understanding of handlers. But not able to replicate the addition of this handler using a seperate file, i get the error ācannot read property āstartswithā of undefinedā
When keeping the handler inside the root index, it adds to the frontity.libaries.source fine. Really not sure why the data isnāt fetching.
Any other insight would appreciated, thank you for the help so far!
Johan4
Making a handler isnāt that complex, although thereās a minor āfeatureā (aka issue) with patterns which look like regular URLās.
The following should work (not tested):
export const acfHandler = {
name: "acf-options",
priority: 10,
pattern: "@acf/options",
func: async ({ link, params, state, libraries }) => {
const { api } = libraries.source;
const { slug } = params;
// 1. fetch the data you want from the endpoint page
const response = await api.get({
endpoint: `/acf/v3/options/options`,
});
// 2. get an array with each item in json format
const items = await response.json();
// 3. add data to source
const currentPageData = state.source.data[link];
Object.assign(currentPageData, {
items: items,
isAcfOptions: true,
});
},
};
export default acfHandler;
brian.tucker5
I was able to get the file to work with this, thanks! Iām still struggling to fetch the data from the endpoint though
brian.tucker6
I was able to get it to work, I had to combine my beforeSSR functions and use a Promise.all on the fetch calls. I am able to see the options now though. Thank you @mburridge & @Johan for the help!