Please see below my index.php query in gists.
It is not your basic query because I have a special drop down menu to filter posts on the home page.
I have a taxonomy set up called Site Position, and my term is called Home Page Exclude. This taxonomy is assigned to my posts.
My question is, how can I exclude posts from my query which have the term called 'home-page-exclude'?
Please see my home page query below.
[[LINK href="https://gist.github.com/6e2e8b4810d21ff67dc6/034598258acf34197d5a77a721a13aae219fe196"]]https://gist.github.com/6e2e8b4810d21ff67dc6/034598258acf34197d5a77a721a13aae219fe196[[/LINK]]
This is what I have tried but doesn't work. Click gist below...
[[LINK href="https://gist.github.com/6e2e8b4810d21ff67dc6/0b1c3200bb8c57383bd9886b9ea0eafcc3a4c9df"]]https://gist.github.com/6e2e8b4810d21ff67dc6/0b1c3200bb8c57383bd9886b9ea0eafcc3a4c9df[[/LINK]]
As you can see from my attempt, I added this...
$tax_query = array (array(
'taxonomy' => 'position',
'terms' => 'home-page-exclude',
'field' => 'slug',
'operator' => 'NOT IN'
));
And then add $tax_query into my query, see below...
<?php wp_reset_query(); $posts = query_posts($query_string . $order . $tax_query); ?>
Some one who post winning answer will get all prize.
Thanks
Ivaylo Draganov answers:
You are passing a wrong thing to query_posts -- you are appending an array to a string. You should use an array for all the arguments:
[[LINK href="https://gist.github.com/3e0658c5ec61094f0287"]]https://gist.github.com/3e0658c5ec61094f0287[[/LINK]]
Josh Cranwell comments:
Peeeeeerfect
Couldnt get it to work, but then added in the { } around the conditons and bingo.
Didnt know you can merge argument like that - pretty cool
Thanks
webGP answers:
Hi,
use this code:
$args = array(
'post_type' => 'post',
'post_satus' => 'publish',
'order' => 'DESC',
'orderby' => 'date',
'tax_query' => array(
array(
'taxonomy' => 'position',
'field' => 'slug',
'terms' => 'home-page-exclude',
'operator' => 'NOT IN'
)
)
);
query_posts($args);
paul de wouters answers:
Don't use query_posts, instead you can use the pre_get_posts filter to modify the main query.
I also suggest using a custom field instead of a taxonomy for filtering the posts out.
http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
you can also check for any $_POST variables inside the filter hook , such as your dropdown select value.