Having trouble with settings terms as array in pre_get_posts

You need to modify the tax_query block of code like below- $q->set( ‘tax_query’, array(array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘term_id’, // Here it would be ‘term_id’ instead of only ‘ID’. ‘terms’ => $allowedCats, ‘operator’ => ‘IN’ // May be it would be ‘IN’ in stead of ‘NOT IN’. Cause you are passing allowed product categories. … Read more

Modify author archive query to combine two queries

The only way that I’ve found to override the main author archive query in a way that will include posts that aren’t created by the specified user is by using the posts_where filter. For example: $post_ids = function_that_gets_desired_post_ids(); add_filter(‘posts_where’, function($where) use ($post_ids){ $post_ids = array_map(function($id){ return (int) $id; }, $post_ids); $in = implode(‘,’, $post_ids); $where … Read more

Problem ID to exclude specific posts from category

Try this: function exclude_single_posts_cat($query) { if ( is_admin() || ! $query->is_main_query() ) return; if ( $query->is_archive() ) { $query->set(‘post__not_in’, array(‘1′,’2′,’3’)); } } add_action(‘pre_get_posts’, ‘exclude_single_posts_cat’); Issue: The issue in your first approach is you have added extra curly brackets and comma.