admin管理员组文章数量:1122832
I have a a query to get post ids of a category
// get ids of posts that belongs to category with id=202
<?php
$args = array( 'showposts' => -1, 'category' => 202, 'post_type' => 'post');
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<?php global $idss; $idss .= "'" .$post->ID . "'" . ","; ?>
<?php endforeach; wp_reset_postdata(); ?>
and then I have a select posts from mysql except ids taken in previous query :
// select posts from mysql table and except ids taken in previous code
<?php
function NotSoPop (){
global $wpdb;
$tops = $wpdb->get_results( "SELECT * FROM wp_popularpostsdata, wp_posts WHERE wp_popularpostsdata.postid = $wpdb->posts.ID AND $wpdb->posts.post_type = 'post' AND ID NOT IN ($ids) ORDER BY pageviews ASC limit 12");
foreach ( $tops as $top ) {
$return .= '<div class="quick_link_item col-md-6 col-lg-4"><a href="'.get_permalink($top->postid).'">' . get_the_title($top->postid) .''. $top->pageviews.'</a></div>';
}
return $return;
}
add_shortcode ("notpop", "NotSoPop");
echo do_shortcode('[notpop]');
?>
I add $ids in NOT IN but its not working.
when I change $ids with static numbers like '10119','10050',... its worked.
where is my mistake?
本文标签: categoriesselect posts from sql except posts from specific category
版权声明:本文标题:categories - select posts from sql except posts from specific category 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736301700a1931264.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论