black_belt black_belt - 1 month ago 8
PHP Question

WHERE NOT Query in Wordpress

I am querying into database using the following code and it is working fine

<?php query_posts(

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

); ?>


Could you please tell me how to add WHERE NOT with the above query.

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

Answer

In wordpress query post add argument 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'
);

So your query post will be like,

query_posts($args);
Comments