最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - how to query a post based on previous page post ID

matteradmin9PV0评论

sorry I probably didn't word the question properly. So i'll describe what im trying to achieve.

I have Page A that has a slider of the different posts. When you click on one it redirects you to the full article(Page B) which also has the same slider. Page B where the full article is has the "next" and "prev" buttons to cycle through the other available posts. For example there are #10 posts in Page A slider, #5 is chosen so this should redirect to the full article of #5 on Page B. And this is where my issues lie.

The slider and query for both page A and B is like this:

<?php 
    $args = array (
        'posts_per_page' => -1,
        'post_type' => 'blog'
    );
    $blog_list = new WP_Query($args);
?>
<?php if( $blog_list->have_posts() ):?>
<?php while( $blog_list->have_posts() ) : $blog_list->the_post();?>

<li class="column swiper-slide">
    <div>
        <?php echo '<a href="'. get_permalink($post->ID) .'">'; ?>
    </div>
</li>
<?php endwhile;?>
<?php endif; ?>
<?php wp_reset_query();

I believe It is a query issue because the URL bar of page B displays the correct link but page B article shows #1 but it should show #5. How should i adjust the query? or if someone could let me know what part of the wordpress doc i should be reading up that would be great as im actually new to this.

Post a comment

comment list (0)

  1. No comments so far