WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Pagination not Found - Help me and Tnks! (3 posts)

  1. Roberto Godoy
    Member
    Posted 1 year ago #

    Pagination not working in custom query, in others works fine!

    <?php 
    
                                        global $wp_query;
                                        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                                        $wp_query->query( 'post_type=any&tag=' . get_query_var('tag') . '&paged='. $paged . '&posts_per_page=4');
                                ?>
    
                                <?php if (have_posts()) : ?>
    
                                        <?php 
    
                                            while ( have_posts() ) : the_post(); 
    
                                                $posttype = get_post_type();
    
                                                $content = '<div class="news-content">
                                                            <div class="news-content-left">
                                                                <div class="news-content-left-date sf-agencyfb">
                                                                    <span class="news-content-left-date-day">%s</span>
                                                                    <span class="news-content-left-date-month">%s</span>
                                                                </div>
                                                                <div class="news-content-left-socialshare">
                                                                    %s
                                                                </div>
                                                            </div>
                                                            <div class="news-content-right">
                                                                <h2>
                                                                    <a href="%s" rel="bookmark" title="Leia completo: %s">
                                                                        %s
                                                                    </a>
                                                                </h2>
                                                                %s
                                                                <p class="' . ($posttype == 'instrutores' ? 'instrutores-text' : 'news-content-right-text') . '">
                                                                    <a href="%s" rel="bookmark" title="Leia completo: %s">
                                                                        %s
                                                                    </a>
                                                                </p>
                                                                ' . ($posttype == 'instrutores' ? '<div class="gid-clear"></div>' : '') . '
                                                                <div class="news-content-right-cats gf-ubuntu">
                                                                    %s: %s
                                                                </div>
                                                                <div class="news-content-right-tags gf-ubuntu">
                                                                    %s: %s
                                                                </div>
                                                            </div>
                                                     </div>';
    
                                                $day        = get_the_time('d');
                                                $month      = get_the_time('M');
                                                $socials    = st_makeEntries();
                                                $url        = get_permalink();
                                                $title      = get_the_title();
                                                $image      = wp_get_attachment_image_src(get_post_thumbnail_id(), 'fullimage');
                                                $text       = excerpt(get_the_content(), 60);
                                                $cats       = get_category_string('link');
                                                $tags       = get_tags_string('link');
                                                $catsCount  =  count(explode(',', $cats));
                                                $tagsCount  =  count(explode(',', $tags));
    
                                                $image_div = '';
    
                                                if($image[0] != ''):
                                                    $image_div  = '<div class="' . ($posttype == 'instrutores' ? 'instrutores-thumb' : 'news-content-right-thumb') . '">
                                                                    <a href="' . $url . '" rel="bookmark" title="' . $title . '">
                                                                        <img src="' . $image[0] . '" alt="' . $title . '">
                                                                    </a>
                                                               </div>';
                                                endif;
    
                                                vprintf($content, array($day, $month, $socials, $url, $title, $title, $image_div, $url, $title, $text, 'Categoria' . ( $catsCount >= 2 ? 's' : ''), $cats,  'Tag' . ( $tagsCount >= 2 ? 's' : ''), $tags));
                                                echo '<div class="content-left-sepline"></div>';
    
                                            endwhile; 
    
                                        ?>
                                <?php endif; ?>
    
                                <?php
                                    wp_pagenavi();
                                ?>
  2. Roberto Godoy
    Member
    Posted 1 year ago #

  3. Roberto Godoy
    Member
    Posted 1 year ago #

    add this in functions and ok.... works fine

    function query_from_tags( $query ) {
                if( $query->is_tag) {
                    $query->set( 'post_type', array( 'agenda', 'events', 'instrutores', 'modalidades', 'parceiros', 'depoimentos', 'sonslider', 'category', 'tag' ) );
                }
            }
            add_action( 'pre_get_posts', 'query_from_tags' );

Topic Closed

This topic has been closed to new replies.

About this Topic