Site icon Hip-Hop Website Design and Development

wp_query->max_num_pages at all times returns 0 on customized publish sort

Hello there I’m growing a theme the place I’ve to load some posts with ajax, in my index web page every thing works correctly, the issue is once I must apply it to customized publish sort, I go the values for a jquery file utilizing wp_localize_script, it go the right worth when I’ve common posts, however it at all times go 0 when I’ve a customized publish sort. Are you able to assist me? Many thanks.

Code to go arguments to my jQuery script

perform core_ajax_init() {

    world $wp_query;

    // Add code to index pages.
    if( !is_admin() ) { //!is_singular()

        // Enqueue jQuery Script to Course of Ajax
        wp_enqueue_script(
            'core_custom',
            get_template_directory_uri(). '/core/js/ajax-load-posts.js',
            array('jquery'),
            '1.0',
            true
        );

        // What web page are we on? And what's the pages restrict?
        $max = $wp_query->max_num_pages;
        $paged = ( get_query_var('paged') > 1 ) ? get_query_var('paged') : 1;
        //echo $max;

        // Add some parameters for the JS.
        wp_localize_script(
            'core_custom',
            'core',
            array(
                'startPage' => $paged,
                'maxPages' => $max,
                'nextLink' => next_posts($max, false)
            )
        );
    }
 }

add_action('template_redirect', 'core_ajax_init');

The next is a template the place I name to print the button to load extra posts

<?php 
world $wp_query;

$found_posts = $wp_query->found_posts;
$per_page = get_option('posts_per_page');
$post_count = $found_posts - $per_page;

if($found_posts > $per_page) :
?>
<div class="row" id="load-more" data-order='999'>
    <div class="col-md-12">
        <div class="load-more-btn">
            <a id="load-more-btn" href="#">     
                <span id="detail-holder">
                    <div id="loader" data-perpage="<?php echo $per_page; ?>"></div>
                    <div class="load-more-text"><?php _e('Click on right here to load extra', CORE_THEME_NAME);  ?></div>
                </span>
            </a>
        </div>
    </div> <!-- /.col-md-12 -->
</div> <!-- /.row -->
<?php endif; ?>

And right here I’ve a snippet the place I make a customized question for a selected publish sort

world $wp_query;
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$wp_query = new WP_Query(array( 'post_type' => 'course', 'order' => 'DESC', 'orderby' => 'date', 'paged' => $paged ));
if($wp_query->have_posts()): ?>

The issue right here is it appears regardless of what number of pages I’ve wp_query var right here at all times return 0 to my perform core_ajax_init(), if I’ve common posts it returns the right variety of pages however for customized publish sort it at all times returns 0. Why? Thanks to your solutions.