David Brossard
David Brossard

Reputation: 13832

In a wordpress post, display the list of posts that belong to the same category as the current post but exclude the current post itself

On my blog, I have a category called "TGIF XACML". At the end of each post, I want to display posts in the same category except for the current post using the wordpress short code

[display-posts category="tgif-xacml"]

I'm trying to figure out how to automatically exclude the current post. The reference page for display-posts does not list that as an option. Is there a way?

If you want to see the current state, check out this example.

Thanks.

Upvotes: 0

Views: 174

Answers (1)

bcedergren
bcedergren

Reputation: 95

I'm not sure about the shortcode, but using functions you could do it like this:

<?php
    global $post;
    $this_post = $post->ID;

    $related_query = new WP_Query( $args = array(
        'post_type' => 'my_post_type',
        'post_status' => 'publish',
        'category' => 'tgif-xacml',
        'post__not_in' => array($this_post)
    ));
?>

Upvotes: 1

Related Questions