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.

order posts by a secondary query that counts items

The way to go is apply custom filters to the WP_Query you are running. add_filter(‘posts_clauses’, function ($clauses, $query) { global $wpdb; // only run the filter for a given query // do your checks and return early if (!$query->is_main_query() || !$query->is_post_type_archive(‘tracklist’)) { return $clauses; } $clauses[‘fields’] .= “, COUNT(items.id) AS track_count”; $clauses[‘join’] .= ” LEFT … Read more

How to exclude woocommerece product category in search results?

function exclude_product_category( $query ) { if ($query->is_search()) { $tax_query = (array) $query->get(‘tax_query’); $tax_query[] = array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => array(‘excluded-category’), ‘operator’ => ‘NOT IN’ ); $query->set(‘tax_query’, $tax_query); } return $query; }

pre_user_query vs pre_get_posts

The pre_get_posts function is a simple query modifier for general “post” queries. If you’re looking to modify the SQL directly for these query I suggest using the post_clauses hook. This hook passes an array of SQL clauses such as: $sql[‘where’] and sql[‘join’] Here you can inject your own custom SQL into the specific clauses. That … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)