Jump to content

Need to exclude latest post in Wordpress


Rory1984

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.