Rory1984 Posted June 19, 2015 Share Posted June 19, 2015 Hi, I have a PHP script that was written by somebody else but I need to edit, it displays the latest issue of a magazine on Wordpress. What I need to do is show the 2 previous posts, excluding the most recent. So change the posts per page to 2, and then exclude the current post. It's probably quite simple but I'm no PHP expert as yet. Here is the script - <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <main id="main"> <section id="latest-edition"> <div class="row"> <?php $args = array( 'post_type' => 'cpt_issue', 'post_status' => 'publish', 'posts_per_page' => 1, 'orderby' => 'date', 'order' => 'DESC' ); if($issues = get_posts($args)): foreach($issues as $issue): list($src,$w,$h) = wp_get_attachment_image_src(get_post_thumbnail_id($issue->ID),'full'); ?> Thanks for your help in advance, Rory Quote Link to comment https://forums.phpfreaks.com/topic/296929-need-to-exclude-latest-post-in-wordpress/ Share on other sites More sharing options...
QuickOldCar Posted June 20, 2015 Share Posted June 20, 2015 https://codex.wordpress.org/Function_Reference/query_posts query_posts('posts_per_page=2&offset=1'); Quote Link to comment https://forums.phpfreaks.com/topic/296929-need-to-exclude-latest-post-in-wordpress/#findComment-1514403 Share on other sites More sharing options...
Rory1984 Posted June 20, 2015 Author Share Posted June 20, 2015 Thanks but that is displaying the full posts. All the code does is identify the category and posts required which it then displays sections of below. I believe it should be something within the array, I tried this $args = array( 'post_type' => 'cpt_issue', 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC' 'post__not_in' => array( $post->ID ) ); but it has an error. Can anybody help? thanks, Rory Quote Link to comment https://forums.phpfreaks.com/topic/296929-need-to-exclude-latest-post-in-wordpress/#findComment-1514426 Share on other sites More sharing options...
maxxd Posted June 21, 2015 Share Posted June 21, 2015 Try: $args = array( 'post_type' => 'cpt_issue', 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC' 'post__not_in' => array( $post->ID ) 'posts_per_page' => 2, 'offset' => 1 ); Quote Link to comment https://forums.phpfreaks.com/topic/296929-need-to-exclude-latest-post-in-wordpress/#findComment-1514511 Share on other sites More sharing options...
Rory1984 Posted June 21, 2015 Author Share Posted June 21, 2015 Perfect, thank you so much, just in time to get it to my client!! Rory Quote Link to comment https://forums.phpfreaks.com/topic/296929-need-to-exclude-latest-post-in-wordpress/#findComment-1514530 Share on other sites More sharing options...
Rory1984 Posted June 21, 2015 Author Share Posted June 21, 2015 The code is just missing the comma , after each line of the array in case anyone else needs to use it Quote Link to comment https://forums.phpfreaks.com/topic/296929-need-to-exclude-latest-post-in-wordpress/#findComment-1514531 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.