实现的WP-PageNavi不适用于我的自定义帖子类型



我实现了我的自定义帖子类型,我需要对更多页面上的所有帖子进行分页。我安装了 wp-pagenavi,但是当我尝试选择例如第 2 页时,URL 发生了变化,但内容将保留在第 1 页上,没有任何变化。

自定义帖子类型是在管理模式下创建的,而不是通过 => register_post_type()

我在代码中是否实现了错误的内容?

 <?php
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        $args = array('post_type' => 'inzeraty',
            'order' => 'ASC',
            'posts_per_page' => 2,
            'paged' => $paged);
        $wp_query = new WP_Query( $args );
            while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
                <div class="col-12">
                    <div class="cpt-news-block mb-3">
                        <div class="row">
                            <div class="col-12 col-sm-6 col-lg-12 col-xl-6">
                                <a class="zoom-picture-hover" href="<?php the_permalink()?>">
                                    <div class="cpt-news-block-image picture">
                <?php $images = acf_photo_gallery('fotka', $post->ID);
                $image = $images[0];
                $id = $image['id']; // The attachment id of the media
                $title = $image['title']; //The title
                $caption= $image['caption']; //The caption
                $full_image_url= $image['full_image_url']; //Full size image url
                //$full_image_url = acf_photo_gallery_resize_image($full_image_url, 762, 580); //Resized size to 262px width by 160px height image url
                $thumbnail_image_url= $image['thumbnail_image_url']; //Get the thumbnail size image url 150px by 150px
                $url= $image['url']; //Goto any link when clicked
                $target= $image['target']; //Open normal or new tab
                $alt = get_field('photo_gallery_alt', $id); //Get the alt which is a extra field (See below how to add extra fields)
                $class = get_field('photo_gallery_class', $id); //Get the class which is a extra field (See below how to add extra fields)
                ?>
                <?php if( !empty($url) ){ ?><a href="<?php echo $url; ?>" <?php echo ($target == 'true' )? 'target="_blank"': ''; ?>><?php } ?>
                <img src="<?php echo $full_image_url; ?>" alt="<?php echo $title; ?>" title="<?php echo $title; ?>">
                <?php if( !empty($url) ){ ?></a><?php } ?>
                                    </div>
                                </a>
                            </div>
                            <div class="col-12 col-sm-6 col-lg-12 col-xl-6">
                                <h2 style="font-size: 20px;">
                                    <a href="<?php the_permalink()?>">
                                        <?php the_title()?>
                                    </a>
                                </h2>
                                <p class="mb-3"><?php the_field('popis_inzeratu')?></p>
                                <a href="<?php the_permalink()?>" class="cpt-news-block-link link-read-more"> <?php
                                    include get_stylesheet_directory() . '/assets/img/svg/icon_arrow.svg';
                                    ?>
                                   <?php echo "More";?>
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            <?php endwhile;?>
        <?php wp_pagenavi( array( 'query' => $wp_query ) ); ?>

我的页面网址:http://tvorba-stranok.eu/ads/

感谢您的任何建议...

安装插件自定义帖子类型 UI 以轻松添加自定义帖子 类型。您必须更改此插件的设置才能使其工作。 当您将重写设置为 false(对于您的自定义帖子类型(时,它将 工作。刷新永久链接设置。

请尝试以下代码。我使用最少的信息进行检查。

 <?php
// Must have wp_pagenavi plugin installed. Custom Post Type names can not clash with page names or 404's will occur on /page/#/ (Utilize Custom Rewrite Slug in CPT)
            // The press release loop
            $the_inzeraty = new WP_Query(array('post_type' => 'inzeraty','posts_per_page' => 10,'paged'=> get_query_var('paged') ));
            // The Loop
            while ($the_inzeraty->have_posts()) : $the_inzeraty->the_post();
                ?>
                <h2><?php the_title(); ?></h2>
                <p><?php the_excerpt(); ?></p>
                <p><a href="<?php echo the_permalink(); ?>" >Read More</a></p>
            <?php endwhile; ?>
            <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(array('query'=> $the_inzeraty));} ?>
<?php wp_reset_postdata();?>

最新更新