Frontity not working with plain permalinks

Iā€™ve set up a new Frontity site and changed state.source.api in frontity.settings.js to point to my WordPress site.

When I load the Frontity site (currently at localhost:3000) I get the following error displayed:

Internal Server Error

When I change it back to the default demo source (https://test.frontity.io/wp-json) everything works fine again.

Compilation succeeds but I also get this error in the terminal when attempting to load the page in the browser:

FetchError: invalid json response body at http://wptest.test/wp-json/wp/v2/posts/?_embed=true&page=1 reason: Unexpected token < in JSON at position 0

OK, figured it out.

I had permalinks set to ā€˜Plainā€™ in WordPress. When I changed permalinks to any other setting, e.g. ā€˜Post nameā€™ then my Frontity site displayed fine.

1 Like

Youā€™re right @zyriab, right now wp-source only works with pretty permalinks. Totally our fault, that should be stated in our docs.

Iā€™m going to add it to the docs todo list :slight_smile:

@community-team I am going to rename this topic from ā€œInternal server errorā€ to ā€œFrontity not working with plain permalinksā€.

I think renaming topics is a good practice. It will help Google to index this page and people to find it.

Feel free to edit this or any other topic :slight_smile:

Iā€™ve received this additional info from @luisherranz:

Yes, because of two reasons:

So wp-source needs permalinks right now but that can be solved in the future if users ask for it, although as far as I know nobody has requested that so far.

1 Like

Hi
I got the same error but after changing the permalink it does not work again.
Plz help.
Thanks

Hi @alee.rezaee

Check that the permalinks in WordPress are set to one of the ā€˜pretty permalinkā€™ settings, not to Plain.

If youā€™re still getting the error can you copy and paste it here, or post a screen grab of the error.

Hi @mburridge
Here you are:

  FetchError: invalid json response body at http://tarjomaanwp/wp-json/wp/v2/posts?_embed=true&page=1 reason: Unexpected token < in JSON at position 0
      at eval (webpack-internal:///./node_modules/node-fetch/lib/index.mjs:276:32)
      at processTicksAndRejections (internal/process/task_queues.js:94:5)
      at populate (webpack-internal:///./node_modules/@frontity/wp-source/src/libraries/populate.ts:9:12)
      at Object.eval (webpack-internal:///./node_modules/@frontity/wp-source/src/libraries/handlers/postTypeArchive.ts:8:13)
      at eval (webpack-internal:///./node_modules/@frontity/wp-source/src/actions.ts:18:101)

Hi @alee.rezaee can you double check your frontity.settings file?

The URL (http://tarjomaanwp/wp-json/wp/v2/posts?_embed=true&page=1 ) shown in the error doesnā€™t look like a valid one. If you take a closer look (http://tarjomaanwp) the top level domain (.com, .org ā€¦) is missing.

Hi
No, it is true. This url is my local url.

Hello again,

I see. What happens when you visit this url http://tarjomaanwp/wp-json/wp/v2/posts?_embed=true&page=1 in the browser? Does it work?

Unfortunately as this is happening in your local environment, we canā€™t reproduce the error to help you. In any case if you set-up an online environment we will be happy to help

Hi
I found the issue. It was because of the installed plugins. The plugin is MB Rest API.
the error was:


( ! ) Fatal error: Uncaught Error: Call to undefined function rwmb_get_registry() in C:\wamp64-new\www\tarjomaanwprepo\wp-content\plugins\mb-rest-api\class-mb-rest-api.php on line 94
( ! ) Error: Call to undefined function rwmb_get_registry() in C:\wamp64-new\www\tarjomaanwprepo\wp-content\plugins\mb-rest-api\class-mb-rest-api.php on line 94
Call Stack
# Time Memory Function Location
1 0.0004 365096 {main}( ) ...\index.php:0
2 0.0006 365384 require( 'C:\wamp64-new\www\tarjomaanwprepo\wp-blog-header.php' ) ...\index.php:17
3 0.2174 6116488 wp( ) ...\wp-blog-header.php:16
4 0.2174 6116512 WP->main( ) ...\functions.php:1255
5 0.2175 6116512 WP->parse_request( ) ...\class-wp.php:729
6 0.2181 6142952 do_action_ref_array( ) ...\class-wp.php:387
7 0.2181 6142952 WP_Hook->do_action( ) ...\plugin.php:544
8 0.2181 6142952 WP_Hook->apply_filters( ) ...\class-wp-hook.php:312
9 0.2181 6143968 rest_api_loaded( ) ...\class-wp-hook.php:288
10 0.2480 7074784 WP_REST_Server->serve_request( ) ...\rest-api.php:305
11 0.2503 7075776 WP_REST_Server->dispatch( ) ...\class-wp-rest-server.php:329
12 0.2572 7272176 WP_REST_Posts_Controller->get_items( ) ...\class-wp-rest-server.php:946
13 0.2912 7947248 WP_REST_Posts_Controller->prepare_item_for_response( ) ...\class-wp-rest-posts-controller.php:312
14 0.4277 8225856 WP_REST_Posts_Controller->add_additional_fields_to_object( ) ...\class-wp-rest-posts-controller.php:1658
15 0.4279 8227192 MB_Rest_API->get_post_meta( ) ...\class-wp-rest-controller.php:403

I had a similar issue disabling plugins and re-activating them fixed it. Wonder why? They were the basics you get with a Hostinger WP install.