hope someone can help me on my customization.

PREMISES i'm very experienced dev, but very beginner on wp. I readed lot of answer on SO but not finding nothing similar to solve my issue.

What i need for my customization is: read $paged param inside normal post type and cutom-post-type.

I handle single.php and single-mytype.php only with custom php code, so i'm not using any loop or other wp-query (data come from external db).

What i need is: When i use get_pagenum_link($p) on post or cpt i obviosully get the right fancy url.

inside post (single.php) the a href (from get_pagenum_link($p)) will show


inside custom-post-type the a href (from get_pagenum_link($p)) will show


Those urls are exactly what i need, but on both if i try to follow link, i always get redirect to main url:


If instead of get_pagenum_link($p) i use other param like add_query_arg(array('pg' => $p), home_url($wp->request).'/') everythings will work well (but ugly url).

I would like to keep using seo friendly urls structure.

NOTE I have tried to register manually my-custom-post-type with 'page' and 'hierarchical' attribute, and also with WCK Post Type Creator plugin created with following options enter image description here

I have also tried (to force) to handle the paged param on function.php like this

add_action( 'pre_get_posts', function ($q){
  if ( !is_admin() && $q->is_main_query() &&
        (is_post_type_archive( 'post' ) || is_post_type_archive( 'ads' ))

  ) {
    $q->set( 'paged', '1' );

Any help how to solve this, i only need $paged be accessible on both post and cpt.

Thanks to all guys.

  • paged is the query var for post archives. Singular posts use the page query var, and the URL format is https://domain.com/post-title/2/, without page. You'll find that these URLs won't redirect. – Milo Apr 23 '18 at 1:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.