CPT and Pages rewrite slug conflict giving me a 404


I’m currently getting a 404 on my site for a page using a CPT archive as the base of its URL.

I previously used this solution to solve the issue – custom taxonomy and pages rewrite slug conflict gives 404 which as been working perfectly.

My issue is now I’ve had a second request for a url which I can’t get to work.

My original code is:

add_filter('rewrite_rules_array', 'add_working_for_lorem');
function add_working_for_lorem($rewrite_rules)
    global $wp_rewrite;

// We only generate them for this page
$page_uri = 'careers/custom-slug';
// Returns site root + '%pagename%'
$page_structure = $wp_rewrite->get_page_permastruct();
// Everywhere you see %pagename% in the structure used to generate rules
// in the next step, replace it with our fixed page name
$wp_rewrite->add_rewrite_tag('%pagename%', "({$page_uri})", 'pagename=');
// This generates the group given above
$page_rewrite_rules = $wp_rewrite->generate_rewrite_rules($page_structure, EP_PAGES);
$rewrite_rules = array_merge($page_rewrite_rules, $rewrite_rules);

    return $rewrite_rules;

However, if I reuse this code even when changing the filter name etc and the variables I get a website error. I’ve tried several different versions so far and happy to include them if that’d help but didn’t want to make the post too long.

TLDR: I currently have one rewritten URL, however now a second is needed I can’t get the same solution I previously used to work.

Max 2 months 0 Answers 12 views 0

Leave an answer