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.
Could you post the code in your component that you are having problems with?
Are you sure that the links are redirecting to the correct URL? In your video I noticed in the console that the data has a value of {is404: true} when you click on one of the hyperlinks. It would also be helpful if you could rerecord the screencast with the URL visible in the browser.
I see that you are making the request from localhost to a remote server (which I assume is your production or staging environment). Could you confirm for me that the changes that youāve been making to your backend (e.g in the .php file) are actually being deployed to that environment?
orballo3
Itās hard to tell whatās wrong without knowing whatās going on in your WP but here are some ideas:
Check the headers of those responses to see if CORS headers are present. As an example, when requesting https://test.frontity.io/wp-json/wp/v2/pages?_embed=true&slug=about-us these are the headers I get:
If those headers are not present then the code you added to functions.php isnāt working. Why? Iād guess something is overriding those headers.
Try to see what filters are making use of that same hook in case one of them comes after yours and changes that. I simple test would be to add to your functions.php something like this:
add_action( 'rest_api_init', function() {
global $wp_filter;
var_dump($wp_filter['rest_pre_serve_request']);
}, 99 );
This will print on the responseās body something like:
Do the posts and pages from before work now? Or is it still the same error?
If not, what are you trying to call? Can you post here the failing request?
modyydom7
if you are on page http://localhost:3000/ and then clicked on a link with href="/about-us/" the error appears
the request is http://wp-local.com/wp-json/wp/v2/pages/?_embed=true&slug=about-us
SantosGuillamot8
I run into a similar problem and I realised it was because I was working on localhost, maybe itās your case too. I guess your web is only able to show the pages and posts that have been fetched from the server. The ones you try to fetch from localhost return that error.
In order to āsolveā it I installed this Chrome extension, moesif, and turned it to on. It doesnāt solve the problem but it lets you see the whole web from local. Once you deploy your app to a real domain, the CORS problems should be solved. You could test it by deploying it to a different domain than the real one (like the one Zeit Now gives you by default, mysite.now.sh).
It looks like the path of the failing request is not /pages but /. And for what I know the only calls that should be done are to /posts and /pages, so it looks like you are doing an extra request for some reason that is failing.
Can you post the code where you are doing this fetchs? Is it in a Link component? Are you doing it manually from somewhere else? Did you wrote any custom handler on your Frontity project that might be interfering?
EDIT: I see you marked @SantosGuillamot response as solution. Is it working now?
luisherranz11
Weāve seen this problem too last week.
It looks like WordPress returns an error for urls ending with a slash: ...wp/v2/posts/?_embed...
and it doesnāt return an error for urls not ending with a slash: ...wp/v2/posts?_embed...
@modyydom could you please confirm if thatās the case? The Chrome devtools in our case looked identical to yours. And if thatās the case, where are you hosting your WP? Is it a one-click install of DigitalOcean?
@modyydom Iāve been able to reproduce the problem. Itās something going on with the REST API - Head Tags plugin. If you turn it off, it should work again.
Weāre going to investigate the issue, open a bug and solve it as soon as possible.
1 Like
modyydom15
Exactly, I can confirm That.
Every many CORS errors are working well now, BUT not all especially when moving from page to another.
Thanks and I really hope to be solved
1 Like
modyydom16
Can you please share the issue ticket here so I can subscribe to it as I canāt find it on github
the Rest API plugin problem, as luisherrant already said
some operations on WP REST that broke CORS
In fact, Iād a custom function active on many installation, that I totally forgot, that was meant to add some rest functionality, but in fact it added some CORS headers that locked some interaction in a silly way as is doing on you.
Try disabling all plugins, mu-plugins and custom theme to check if thereās something that is going on in your installation.
Iād a similar problem even on a blank installation, but, as I said in the other post, the problem is related to the category SLUG that must be ācategoryā to let Frontity fetch categories data, not CORS.