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