doulian5857 2013-07-09 00:13
浏览 213
已采纳

Wordpress post__not_in()函数不排除小部件数组中的当前帖子

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');
  • 写回答

2条回答 默认 最新

  • duanhai7274 2013-07-12 17:52
    关注

    OK I found the solution. The id was not passing to the widget:

    'post__not_in' => array (get_the_ID()),
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行