Wordpress shortcode pagination
<p>I've created a shortcode for custom post with advanced custom fields. All works correctly except the pagination. I've tried all of the options I can see on other posts, but none work for me. Pagination is working on custom post pages.</p>

<pre><code>function link_carstwo( $atts ) {
extract(shortcode_atts(array(
    'cartype' =&gt; 'porsche',
    'section' =&gt; 'make'
), $atts));
$big = 999999999; // need an unlikely integer

echo paginate_links( array(
'base' =&gt; str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' =&gt; '?paged=%#%',
'current' =&gt; max( 1, get_query_var('paged') ),
'total' =&gt; $the_query-&gt;max_num_pages
) );
$list = ' ';
echo '&lt;div id="car-container"&gt;
  &lt;ul id="carlist"&gt;';
//Setup the query to retrieve the posts that exist under each term


        global $post;
    $posts = new WP_Query (array(
          'post_type' =&gt; 'cars',
          'orderby' =&gt; 'menu_order',
          'order' =&gt;  'ASC',
          $section =&gt; $cartype,
          'post_status' =&gt; 'publish',
          'posts_per_page' =&gt; 9,
          'paged' =&gt; $paged,
          ));

        // Here's the second, nested foreach loop that cycles through the posts associated with this category
        while ( $posts-&gt;have_posts() ) { $posts-&gt;the_post();
         ////set up post data for use in the loop (enables the_title(), etc without specifying a post ID--as referenced in the stackoverflow link above)
$price = get_field('price', $post-&gt;ID);
$car_image = get_field('car_image', $post-&gt;ID);
$image_position = get_field('image_position', $post-&gt;ID);
$make = get_field('make', $post-&gt;ID);
$year = get_field('year', $post-&gt;ID);
$date_purchased = get_field('date_purchased', $post-&gt;ID);
$finance_type = get_field('finance_type', $post-&gt;ID);
$job_title = get_field('job_title', $post-&gt;ID);
$model = get_field('model', $post-&gt;ID);

$list .=  '&lt;li class="carbox"&gt; 
&lt;p&gt;TEST&lt;/p&gt;
&lt;div class="image2"  style="background-image:url(' . $car_image .');background-position: ' . $image_position . ' center;"&gt;&lt;/div&gt;
&lt;p class="car"&gt; '.$make.' ' . $model . ' ' . $year . ' &lt;/br&gt; £ ' . $price . '        ' . $date_purchased . '&lt;/p&gt;
&lt;p class="finance"&gt;' . $finance_type . '&lt;/p&gt;
&lt;p class="fademeSmall"&gt; ' . $job_title . '&lt;/p&gt;
&lt;p class="linked"&gt;&lt;a href="'. get_permalink($post-&gt;ID) .'" class="orangeButtonRound"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;';

        } 
'&lt;/ul&gt;&lt;/div&gt;';


return 


 '&lt;div class="navigation centerWidth"&gt;' 
 . $list 
 .the_posts_pagination( array(
 'mid_size'  =&gt; 2,
 'prev_text' =&gt; __( '&lt;', 'textdomain' ),
 'next_text' =&gt; __( '&gt;', 'textdomain' ),
 ) ) 
 . '&lt;div class="nav-previous"&gt;' . get_next_posts_link( __( '&lt;span class="meta-nav"&gt;&amp;larr;&lt;/span&gt; Older posts' ) ) . '&lt;/div&gt;'
 . '&lt;div class="nav-next"&gt;' . get_previous_posts_link( __( 'Newer posts &lt;span class="meta-nav"&gt;&amp;rarr;&lt;/span&gt;' ) ) . '&lt;/div&gt;'
 . 'TEST&lt;/div&gt;' .
 wp_reset_query();
 }



add_shortcode( 'car-gridtwo', 'link_carstwo' );
</code></pre>