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条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧