It is still somewhat a mystery what you need looking at all the comments and the question content.
Here are two approaches that should work
FOR PAGES
I have written a complete function that will paginate any (or almost any) query except on single post pages. It also works out of the box for static front pages. I'm not going to go into details regarding the get_paginated_numbers()
pagination function. Everything you need to know is discussed in my answer here, so feel free to check it out. And don't forget to modify it to suit your exact needs.
Here is a basic shortcode to showcase the usage
add_shortcode( 'paginate_shortcode', function ()
{
if ( get_query_var('paged') ) {
$current_page = get_query_var('paged');
}elseif ( get_query_var('page') ) {
$current_page = get_query_var('page');
}else{
$current_page = 1;
}
$q = new WP_Query( ['posts_per_page' => 1, 'paged' => $current_page] );
return $q->posts[0]->post_title . '</br>' . get_paginated_numbers( ['query' => $q] );
});
You can use [paginate_shortcode]
on any page, it will display something like this
Note that the post title changes as the links changes
FOR SINGLE POSTS
Single posts with paginated sub queries are not really meant to be. If you are going to use your shortcode on a single post page (which I discourage) like for related posts, you can use the approach that I posted in this answer. It is quite extensive, so I'm not going to repost it here. Feel free to check it out and modify as needed
$wp_query
is your issue, this is the main query object global. You should use the variable used by your custom query