bluerainsky
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Forum: Fixing WordPress
In reply to: category__not_in doesn't work in searchthanks for helping!
below is the code that i am using. i also have what you suggested ‘search_filter’ function in my function.php file. However, it’s still not working. can you please suggest how i can fix this problem?
function search_filter($query) { if ( !is_admin() && $query->is_main_query() ) { if ($query->is_search) { $query->set('category__not_in', array( 1164 ) ); } } } add_action('pre_get_posts','search_filter');<?php global $wp_query, $query_string; $paged = get_query_var('paged'); $term = get_query_var('s'); $args = array ( 'posts_per_page' => '15', 'paged' => $paged, 'order' => 'DESC' ); query_posts($args); $numpages = $wp_query->max_num_pages; $numposts = $wp_query->found_posts; ?> <?php if( have_posts() ) : ?> <?php while( have_posts() ) : the_post(); ?> <a>"> <span><?php the_title(); ?></span> </a> <?php endwhile; ?> <?php endif; ?> <?php wp_reset_query(); ?> <?php if ( $numpages > 1 && $paged < $numpages) : ?> <?php echo next_posts_link( ' » '); ?> <?php endif; ?> <?php if ( $paged > 1 ) : ?> <?php echo previous_posts_link( ' « ' ); ?> <?php endif; ?>Forum: Fixing WordPress
In reply to: category__not_in doesn't work in searchI have tried using array for category__not_in parameter, still the same results, category 1164 posts still shows up.
i am using custom theme. The search.php just has basic query and then loop through the query to display each post. I am using the exact same code for search and for category. The category__not_in parameter works in category, and 1164 is removed. But in search, it doesn’t work.
$paged = get_query_var( 'paged' ); $cat = get_query_var( 'cat' ); $term = get_query_var('s'); $order = 'DESC'; $args = array( 'posts_per_page' => '15', 'cat' => $cat, 'paged' => $paged, 'category__not_in' => array('1164'), 'order' => $order ); $loop = new WP_Query($args);
Viewing 2 replies - 1 through 2 (of 2 total)