colbyfayock/next-wordpress-starter

Get 404 on pages

eliawk opened this issue · 4 comments

Hello,
everything work fine but if I visit any pages I get a 404.
Posts, categories,... everything else is working correctly.

Schermata 2022-04-20 alle 18 27 56

@colbyfayock I've fixed removing the baseurl form the uri:

  const paths = pages
    .filter(({ uri }) => typeof uri === 'string')
    .map(({ uri }) => {
      const segments = uri
        .replace('http://localhost:3000', '')
        .split('/')
        .filter((seg) => seg !== '' && seg !== undefined);
      return {
        params: {
          slugParent: segments.shift(),
          slugChild: segments,
        },
      };
    });

how did you make this working without this fix?

hey i'm not really sure about this one? could it be a custom setting you have for permalinks or how URLs are returned? haven't seen this issue before

@colbyfayock yes it was my fault. I've had this:

function custom_frontend_url($permalink, $post)
{
  $custom_permalink = str_replace(home_url(), HEADLESS_URL,  $permalink);
  return $custom_permalink;
};

add_filter('page_link', 'custom_frontend_url', 10, 2);
add_filter('post_link', 'custom_frontend_url', 10, 2);
// If you use custom post types also add this filter.
add_filter('post_type_link', 'custom_frontend_url', 10, 2);

in order to change the links from the WP be, but this affects also the uri in the grapqhl queries.

ah thanks for sharing, glad you were able to figure it out! is this something that can be avoided in the starter? i tend to think that's a custom feature that wouldn't make sense in the starter beyond this issue that people can search for. thoughts?