I am using the following code to display posts from same category on a current post page:

global $post;
$categories = get_the_category();
foreach ($categories as $category[0]) {
if ($ceker == false){
    <h3 class="naslovostalih">Other posts from this category:</h3>
    <ul class="clanciostalih">
    $args = array(
        'numberposts' => 10,
        'category' => $category[0] -> term_id, 
        'exclude' => $post->ID
    $posts = get_posts($args);
        foreach($posts as $pz) { ?>
                $title = $pz->post_title;
                $link = get_permalink($pz->ID);
                printf('<a class="linkpost" title="%s" href="%s">%s</a>', $title, $link, $title);
                echo get_the_post_thumbnail($pz->ID, 'thumb-232');
                echo '<div id="excerptcu">';
                $pz = $pz->post_excerpt;
if (strlen($pz) > 160) {
$pz = substr($pz,0,strpos($pz,' ',160)); } ;
$pz = $pz . ' ...';
echo apply_filters('the_excerpt',$pz);
                echo '</div>';
               <p class="more-link-wrapper2"><?php printf('<a class="read-more     button" title="%s" href="%s">Opširnije</a>', $title, $link, $title);?></p>
        <?php } // end foreach ?>
<?php } // end if ?>

It works almost perfect, but the problem is that Other posts are doubled so I have this kind of output:

POST1 (which is in cat blizzard and in category europe)

Content of POST1

Other posts from this category: (should take just posts from the first category and that is blizzard)


So the “other posts” are doubled and I cant figure it out why.

Any ideas?

Read more here: Get just one category, in which the post is in and eliminate the double posts


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: