How can I put two variables in post__not_in
like this:
'post__not_in' => $excludeHome, $excludePostSlide
When I do this only posts from first variable don’t show up from the others show up.
I can do that with array push like below but is there any different way to do it?
@php
wp_reset_postdata();
global $excludeHome;
global $excludePostSlide;
array_push($excludeHome, $excludePostSlide[0], $excludePostSlide[1], $excludePostSlide[2], $excludePostSlide[3], $excludePostSlide[4], $excludePostSlide[5]);
$args = [
'post_type' => 'post',
'orderby' => 'date',
'category_name' => 'auto',
'posts_per_page' => 6,
'no_found_rows' => true,
'post__not_in' => $excludeHome,
];
$querySlider = new WP_Query($args);
@endphp
2
Answers
try to pass the parameter as
array
:According to the
wp_query
Docs,post__not_in
accepts an array of post ids.$excludeHome
and$excludePostSlide
variables are actually arrays. So make sure that they are arrays.array_push
function, it’s better to use aforeach
loop on the$excludePostSlide
array, rather than trying to push them by their index number!