I am trying to modify (refine?) Worpress search results by using WP_Query, just as it's explained in the Codex. The snippet featured in that article is on the top of the Search Template PHP file, and all results are displaying accordingly.
When I try to append the WP_Query array with arguments of my choice, to create a modified query (for example: posts containing term user searches for, not included in a certain taxonomy), WP_Query completely ignores the appended arguments and gives me the original search results all over again.
Code below:
$search = new WP_Query(array( 'taxonomy' => 'media', 'field' => 'image', 'operator' => 'NOT IN'));
I also tried it this way, but I have a feeling it's completely wrong:
<?php
global $query_string;
$query_args = explode("&", $query_string);
$search_query = array();
foreach($query_args as $key => $string) {
$query_split = explode("=", $string);
$search_query[$query_split[0]] = urldecode($query_split[1]);
} // foreach
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'media',
'field' => 'slug',
'terms' => 'media',
'operator' => 'NOT IN'
)
),
$search_query
);
What follows is the usual:
if ( $search->have_posts() ) :
while ($search->have_posts() ) : $search->the_post(); ?>
I am not very fluent when it comes to coding, but trying to teach myself the quirks of Wordpress as a CMS. I read through replies on this site, none of the methods used did it for me, though.
Can you see what I'm doing wrong? Thanks!