WordPress : Deux requêtes sur la même page avec pagination

Publié par Jean-Michel le

J’essaie de mettre deux requêtes sur la même page avec la pagination. Mais la pagination de l’un interfère avec l’autre. Comment puis-je faire cela avec deux paginations indépendantes

<div class="row list-group">
    <?php

        function  query_group_by_filter($groupby){
            global $wpdb;

            return $wpdb->postmeta . '.meta_value ';
        }
        global $paged, $wp_query, $wp;

        $args = wp_parse_args($wp->matched_query);
        if ( !empty ( $args['paged'] ) && 0 == $paged ) {
            $wp_query->set('paged', $args['paged']);
            $paged = $args['paged'];
        }
        $temp = $wp_query;
        $wp_query= null;
        add_filter('posts_groupby', 'query_group_by_filter');
        $args = array(
        'post_type' => 'a-casa',
        'posts_per_page' => 1,
        'paged' => $paged,
        'meta_key'      => 'semana',
        'post_status' => 'publish',
        'order' => 'ASC',
        );
        $wp_query = new WP_Query($args);
        //$wp_query->query('post_type=post&posts_per_page='.$betubeVideoCount.'&paged='.$paged);
        $current = -1;
        $current2 = 0;
        $post_id = $post->ID;
        remove_filter('posts_groupby', 'query_group_by_filter');
    ?>
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); $current++; $current2++; ?>
    <div class="large-12 columns">
        <div style='text-align: center;'>
            <h3>Videos da Semana: <?php $atrizweek = get_field('semana'); echo $atrizweek; ?></h3>

            <h4><?php
                $atriz_id = get_field('atrizes');

                $atriz = get_post( $atriz_id[0]);

            echo "<a style='text-align: center;' href='#'>{$atriz->post_title}</a>"; ?></h4>
        </div>
    </div>

    <div class="large-12 columns"><div class="pagination-semana">

        <div class="nav-previous alignleft"><?php next_posts_link( 'Semana Anterior' ); ?></div>
        <div class="nav-next alignright"><?php previous_posts_link( 'Próxima Semana' ); ?></div>

    </div></div>
    <div class="item large-4 medium-6 columns end <?php echo $myClass; ?>">

    </div><!--item large-4-->

    <?php endwhile; ?>


    <?php wp_reset_query(); ?>
</div><!--new-all-->

<!-- NEW MY CUSTOM-->
<div class="tabs-content" data-tabs-content="newVideos">
    <div class="tabs-panel is-active" id="new-all">
        <div class="row list-group">
            <?php
                global $paged, $wp_query, $wp;
                $args = wp_parse_args($wp->matched_query);

                if ( !empty ( $args['paged'] ) && 0 == $paged ) {
                    $wp_query->set('paged', $args['paged']);
                    $paged = $args['paged'];
                }
                $temp = $wp_query;
                $wp_query= null;

                $args = array(
                'post_type' => 'a-casa',
                'posts_per_page' => $betubeVideoCount,
                'paged' => $paged,
                'meta_key'      => 'semana',
                'meta_value'    => $atrizweek,
                'post_status' => 'publish',
                'orderby' => 'date',
                );
                $wp_query = new WP_Query($args);


                //$wp_query->query('post_type=post&posts_per_page='.$betubeVideoCount.'&paged='.$paged);
                $current = -1;
                $current2 = 0;
                $post_id = $post->ID;

            ?>
            <?php while ($wp_query->have_posts()) : $wp_query->the_post(); $current++; $current2++; ?>
            <div class="item large-4 medium-6 columns end <?php echo $myClass; ?>">
                <div class="post thumb-border">
                    <div class="post-thumb">
                        <?php
                            if( has_post_thumbnail()){
                                echo get_the_post_thumbnail();
                                }else{
                            ?>
                            <img src="<?php echo get_template_directory_uri() . '/assets/images/nothumb.png' ?>" alt="No Thumb"/>
                            <?php
                            }
                        ?>
                        <a href="<?php the_permalink(); ?>" class="hover-posts">
                            <span><i class="fa fa-play"></i><?php esc_html_e( 'Watch Video', 'betube' ); ?></span>
                        </a>
                    </div><!--post thumb-border-->
                </div><!--item large-4-->
                <?php endwhile; ?>

                <div class="large-12 columns"><?php
                    global $wp_rewrite;
                    $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;

                    $classiera_pagination = array(
                    'base' => @add_query_arg('page','%#%'),
                    'format' => '',
                    'total' => $wp_query->max_num_pages,
                    'current' => $current,
                    'show_all' => false,
                    'type' => 'plain',
                    );

                    if( $wp_rewrite->using_permalinks() )
                    $classiera_pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) . 'page/%#%/', 'paged');

                    if( !empty($wp_query->query_vars['s']) )
                    $classiera_pagination['add_args'] = array('s'=>get_query_var('s'));

                    echo '<div class="pagination">' . paginate_links($classiera_pagination) . '</div>';
                ?></div>
            </div><!--row list-group-->
            <?php wp_reset_query(); ?>
        </div><!--new-all-->

Solution n°1 trouvée

Please use below code hope it's work for you
<div class="row list-group">
    <?php

        function  query_group_by_filter($groupby){
            global $wpdb;

            return $wpdb->postmeta . '.meta_value ';
        }
        global $paged, $wp_query, $wp;

        $args = wp_parse_args($wp->matched_query);
        if ( !empty ( $args['paged'] ) && 0 == $paged ) {
            $wp_query->set('paged', $args['paged']);
            $paged = $args['paged'];
        }
        $temp = $wp_query;
        $wp_query= null;
        add_filter('posts_groupby', 'query_group_by_filter');
        $args = array(
        'post_type' => 'a-casa',
        'posts_per_page' => 1,
        'paged' => $paged,
        'meta_key'      => 'semana',
        'post_status' => 'publish',
        'order' => 'ASC',
        );
        $wp_query = new WP_Query($args);
        //$wp_query->query('post_type=post&posts_per_page='.$betubeVideoCount.'&paged='.$paged);
        $current = -1;
        $current2 = 0;
        $post_id = $post->ID;
        remove_filter('posts_groupby', 'query_group_by_filter');
    ?>
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); $current++; $current2++; ?>
    <div class="large-12 columns">
        <div style='text-align: center;'>
            <h3>Videos da Semana: <?php $atrizweek = get_field('semana'); echo $atrizweek; ?></h3>

            <h4><?php
                $atriz_id = get_field('atrizes');

                $atriz = get_post( $atriz_id[0]);

            echo "<a style='text-align: center;' href='#'>{$atriz->post_title}</a>"; ?></h4>
        </div>
    </div>

    <div class="large-12 columns"><div class="pagination-semana">

        <div class="nav-previous alignleft"><?php next_posts_link( 'Semana Anterior' ); ?></div>
        <div class="nav-next alignright"><?php previous_posts_link( 'Próxima Semana' ); ?></div>

    </div></div>
    <div class="item large-4 medium-6 columns end <?php echo $myClass; ?>">

    </div><!--item large-4-->

    <?php endwhile; ?>


    <?php wp_reset_postdata(); ?>
</div><!--new-all-->

<!-- NEW MY CUSTOM-->
<div class="tabs-content" data-tabs-content="newVideos">
    <div class="tabs-panel is-active" id="new-all">
        <div class="row list-group">
            <?php
                $args2 = wp_parse_args($wp->matched_query);

                if ( !empty ( $args2['paged'] ) && 0 == $paged ) {
                    $wp_query->set('paged', $args2['paged']);
                    $paged = $args2['paged'];
                }
                $temp = $wp_query;
                $wp_query= null;

                $args2 = array(
                'post_type' => 'a-casa',
                'posts_per_page' => $betubeVideoCount,
                'paged' => $paged,
                'meta_key'      => 'semana',
                'meta_value'    => $atrizweek,
                'post_status' => 'publish',
                'orderby' => 'date',
                );
                $wp_query2 = new WP_Query($args2);


                //$wp_query->query('post_type=post&posts_per_page='.$betubeVideoCount.'&paged='.$paged);
                $current = -1;
                $current2 = 0;
                $post_id = $post->ID;

            ?>
            <?php while ($wp_query2->have_posts()) : $wp_query2->the_post(); $current++; $current2++; ?>
            <div class="item large-4 medium-6 columns end <?php echo $myClass; ?>">
                <div class="post thumb-border">
                    <div class="post-thumb">
                        <?php
                            if( has_post_thumbnail()){
                                echo get_the_post_thumbnail();
                                }else{
                            ?>
                            <img src="<?php echo get_template_directory_uri() . '/assets/images/nothumb.png' ?>" alt="No Thumb"/>
                            <?php
                            }
                        ?>
                        <a href="<?php the_permalink(); ?>" class="hover-posts">
                            <span><i class="fa fa-play"></i><?php esc_html_e( 'Watch Video', 'betube' ); ?></span>
                        </a>
                    </div><!--post thumb-border-->
                </div><!--item large-4-->
                <?php endwhile;  ?>

                <div class="large-12 columns"><?php
                    global $wp_rewrite;
                    $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;

                    $classiera_pagination = array(
                    'base' => @add_query_arg('page','%#%'),
                    'format' => '',
                    'total' => $wp_query->max_num_pages,
                    'current' => $current,
                    'show_all' => false,
                    'type' => 'plain',
                    );

                    if( $wp_rewrite->using_permalinks() )
                    $classiera_pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) . 'page/%#%/', 'paged');

                    if( !empty($wp_query->query_vars['s']) )
                    $classiera_pagination['add_args'] = array('s'=>get_query_var('s'));

                    echo '<div class="pagination">' . paginate_links($classiera_pagination) . '</div>';
                ?></div>
            </div><!--row list-group-->
            <?php   wp_reset_postdata(); ?>
        </div><!--new-all-->

Catégories : Wordpress

Jean-Michel

Jean-Michel est en charge de la partie blog du site. Il met en place la stratégie de contenu et répond aux questions fréquentes sur Wordpress.

0 commentaire

Laisser un commentaire

Avatar placeholder

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *