0

I am using Wordpress 4.3 and WPML plugin. I used category filter on theme, front page of site only displays posts in "English" category. Category id is 62.

Code is below:

<?php
                $count_posts = wp_count_posts();
                $page = isset($wp_query->query['paged']) ? (int)$wp_query->query['paged'] : 1;
                $count_post = 9;
                $args = array(
                    'posts_per_page'   => $count_post,
                    'offset'           => ($page-1) * $count_post,
                    'category'         => '62',
                    'orderby'          => 'date',
                    'order'            => 'DESC',
                    'post_type'        => 'post',
                    'post_status'      => 'publish',
                    'suppress_filters' => true
                );
                $posts_array = get_posts( $args );
                ?>

Originally the theme didn't contain pagination so I implemented something like this by comparing the code to another theme:

<div class="row text-center">
            <hr>
            <nav>
                <ul class="pagination m30-0">
                    <?php
                    if($page > 1) {
                        $i = $page - 1;
                        $url = "href='../../page/$i/'";
                    ?>
                    <li>
                      <a <?=($page==$i?'':$url)?> aria-label="Previous">
                        <span aria-hidden="true">&larr;</span>
                      </a>
                    </li>
                    <?php
                        }
                        for($i = 1;$i <= $maxpages;$i++){
                            $url = "href='".($page >= 1 ? "../../": "")."page/$i/'";
                            ?>
                            <li class='<?=($page==$i?'active':'')?>'><a <?=($page==$i?'':$url)?>><?=$i?></a></li>
                            <?php
                        }
                    ?>
                    <?php
                    if( $page + 1 <= $maxpages ) {
                        $i = $page + 1;
                        $url = "href='".($page >= 1 ? "../../" : "")."page/$i/'";
                    ?>
                    <li>
                      <a <?=($page==$i?'':$url)?> aria-label="Next">
                        <span aria-hidden="true">&rarr;</span>
                      </a>
                    </li>
                    <?php
                    }
                    ?>
                </ul>
            </nav>

        </div>

As expected resulting pagination displays more pages than I have in English category. I have about 4 pages, but pagination displays 4 more pages which are empty. I think pagination is counting posts in other languages as well.

What would be the correct way to implement category filter to pagination as well? Thanks.

0

Try changing 'suppress_filters' => false;

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.