The problem is that anytime you try and go to a post such as:
http://example.com/test/articles/example-slug/
↑ ↑
| └ attempts to match "articles" as name/pagename query variable
└ matches post_type "test"
WordPress is trying to match /test/articles
, as in articles
being a post of post_type === test
.
Instead you need to add a custom rewrite rule (then flush your rewrite rules):
function wpse221472_custom_rewrite_rules() {
add_rewrite_rule(
'^test/(articles)/(.*)?',
'index.php?post_type=$matches[1]&name=$matches[2]',
'top'
);
}
add_action('init', 'wpse221472_custom_rewrite_rules');
This will match:
$matches[1] $matches[2]
↓ ↓
http://example.com/test/articles/example-slug/
Not sure that this is the best approach but it will work, just be aware that you cannot have a post unde the test
post_type
that has a slug of articles
because it won’t be matched; our re-write rule will override it.
If that doesn’t bother you then the above should suffice.