1

我正在使用以下代码查询数据库,它工作正常

<?php query_posts( 

'post_type=gallery&posts_per_page='.$gnum.'&paged='.$paged.'&orderby=title&order=ASC'

 ); ?>

您能否告诉我如何在上述查询中添加 WHERE NOT。

( WHERE ID != '400' AND ID!='401')

4

3 回答 3

3

在 wordpress 查询后添加参数post__not_in

'post__not_in' => array(400, 401)

$args = array(
     'post_type' => 'gallery',
     'posts_per_page' => $gnum,
     'post__not_in' => array(400, 401),
     'paged' => $paged,
     'orderby' => 'title',
     'order' => 'ASC'
);

所以你的查询帖子会像,

query_posts($args);
于 2013-04-01T11:17:29.317 回答
1

试试这个...

$args = array(
           'post_type' => 'gallery',
           'posts_per_page' => $gnum,
           'paged' => $paged,
           'orderby' => 'title',
           'order' => 'ASC',
           'post__not_in' => array(6,2,8) 
        );
query_posts( $args );
于 2013-04-01T11:15:42.437 回答
0
<?php query_posts( 

'post_type=gallery&posts_per_page='.$gnum.'&paged='.$paged.'&orderby=title&ID='-400,-401'&order=ASC'

 ); ?>
于 2013-04-01T11:15:14.237 回答