Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude Post ID from Wordpress Query

I have created a wordpress query and I am trying to exclude one post with the id of 1293.

Here is the query I have written so far:

<?php 
$my_query = new WP_Query(array (
'post__not_in' => array(1293), 
'post_type' => 'product',
'posts_per_page' => '100'
));
?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

<?php the_title(); ?>
<?php the_content(); ?>

<?php endwhile; ?>
<?php wp_reset_query(); ?>
like image 457
Alan Carr Avatar asked Sep 03 '25 02:09

Alan Carr


1 Answers

post__not in expects an array. Try the following:

$my_query = new WP_Query(array (
    'post__not_in' => array(1293), 
    'post_type' => 'product',
    'posts_per_page' => '100'
));
like image 187
markusthoemmes Avatar answered Sep 04 '25 22:09

markusthoemmes