So based on the comments, you confirmed that you’re using a custom Page (i.e. post of the page
type) as the post type’s archive, which means you either have both the media
and actualites
Pages (where actualites
is a child of the media
Page) or that you used a parent Page for the CPT archive.
And normally, going to page 2, 3, etc. of a Page will not going to result in a 404 error; however, your post type’s rewrite slug is medias/actualites
, therefore medias/actualites/page/2
(or page/3
, page/4
, etc.) will result in the 404 error because WordPress treats the URL as a single CPT request.
But fortunately, you can get rid of the 404 error by using a custom rewrite rule which can be added using add_rewrite_rule()
:
// First, register the CPT.
register_post_type( 'actualite', array( ... your args ... ) );
// Then add the rewrite rule.
// Note: With pagename, you must use the full page path, i.e. <parent slug>/<child slug>
add_rewrite_rule(
'^medias/actualites/page/(\d+)/?$',
'index.php?pagename=medias/actualites&paged=$matches[1]',
'top'
);
/* Or if using a parent Page:
add_rewrite_rule(
'^medias/actualites/page/(\d+)/?$',
'index.php?pagename=your-cpt-archive&paged=$matches[1]',
'top'
);
*/
PS: Don’t forget to flush the rewrite rules and just use get_query_var( 'paged' )
to get the page number.
And if you already have a custom rewrite rule, you can add it to the question and I’ll help you fix it.