WordPress post__not_in() function not excluding current post in widget array

This is a widget that came with a theme and it’s not excluding the listing item from the sidebar. This pulls 3 real estate listings from the same area. But it fails to exclude the current item.

Must be some issue with post__not_in() but I don’t see the issue. Anyone know that function?

function listingsInSameAreaWidget() { ?>

<aside id="other-listings-in-same-area" class="widget left">
<h4><?php _e('Other Listings in Same Area', 'theme_textdomain'); ?></h4>
<ul id="newlistings">
<?php
$author = get_the_author_meta('ID');
$city = get_the_term_list(ID, 'city');
$post_id = get_post($post->ID)->ID;
$args = array(
    'post_type' => 'listings',
    'city' => $city,
    'post__not_in' =>$post->ID,
    'posts_per_page' => 3
);

//query_posts($args);
query_posts( array(
    'post_type' => 'listings',
    'city' => $city,
    'post__not_in' =>$post->ID,
    'posts_per_page' => 3, )

);  
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> 
    <li>
        <?php ct_status_sm(); ?>
        <?php ct_first_image_tn_left(); ?>
        <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
        <p class="location"><?php city_and_state(); ?></p>
        <p class="propinfo"><?php beds(); ?> <?php _e('Bed', 'theme_textdomain'); ?>, <?php baths(); ?> <?php _e('Bath', 'theme_textdomain'); ?></p>
        <div class="clear"></div>
    </li> 
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
</ul>
</aside>

<?php
}

register_sidebar_widget('Other Listings in Same Area', 'listingsInSameAreaWidget');

Related posts

Leave a Reply

2 comments