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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.