Use posts_where to exclude posts ids from wp_query

Instead of using posts_where it is a better idea to use pre_get_posts filter. Here is the code I end up implementing: add_filter( ‘pre_get_posts’, ‘hide_unwanted_posts_filter’ ); function hide_unwanted_posts_filter( $query ) { global $current_user; get_currentuserinfo(); $user_id = $current_user->ID; $key = ‘unwanted_posts’; $unwanted_posts = get_user_meta($user_id,$key,true); if(is_user_logged_in() && !empty($unwanted_posts) && !$query->is_admin) { $query->set(‘post__not_in’, $unwanted_posts ); // id of page … Read more

Exclude post category in a blog page

In your functions.php file, use pre_get_posts and swap out the -1 in the following code with the category I.D you want to exclude from your posts page. function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘cat’, ‘-1’ ); } } add_action( ‘pre_get_posts’, ‘exclude_category’ );

How exclude 3 latest posts of a category in query_posts

I’d do it like this: $excluded_posts = array(); // select first 3 featured posts ordered by date $args = array ( ‘post_type’ => array( ‘post’ ), ‘category_name’ => ‘featured’, ‘posts_per_page’ => ‘3’, ‘order’ => ‘DESC’, ‘orderby’ => ‘date’, ‘ignore_sticky_posts’ => true, // or maybe not? ); $query = new WP_Query( $args ); while ( $query->have_posts() … Read more

wp_list_categories not excluing multiple ids

I’m pretty sure this is a Codex error and that the string that exclude parameter expects for wp_list_categories() is really meant for non-hierarchical tags, such as blue,red where hierarchical you need to pass an array of integers: $args = array( ‘orderby’ => ‘ID’, ‘show_count’ => 1, ‘taxonomy’ => ‘portfolio-type’, ‘use_desc_for_title’ => 1, ‘echo’ => 0, … Read more

Exclude latest post from WP_Query taxonomy term loop

wp_query has the offset parameter which you can use to skip posts, e.g. $args = array( ‘post_type’ => ‘video’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘tax-video’, ‘field’ => ‘slug’, ‘terms’ => ‘t-o-t-w’, ), ), ‘posts_per_page’ => ‘8’, ‘offset’ => 1, // excludes the first post in the query ); you may just be over thinking … Read more

How to get post with slug and exclude categories

Please read this Codex page why you should not use query_posts(). If you really want to use query_posts(): query_posts( ‘name’ => ‘test’, ‘category’ => ‘-15’ // notice “minus 15” ); The right way to exclude category: $query = new WP_Query( array( ‘name’ => ‘test’, ‘category__not_in’ => array(15) ) ); if ( $query->have_posts() ) { ….. … Read more

Exclude page from loop results

You need the WP_Query documentation. WP_Query is very powerful, and you can do a lot with it 🙂 In your case, I don’t think exclude is a valid parameter. What you’re probably looking for is this: $query->set( ‘post__not_in’, array( 34 ) ); Here’s the Post & Page Parameters section of the documentation, which covers this … Read more

How can I exclude a specific ID from this line of code?

On a seperate note, ‘caller_get_posts’ was deprecated in version 3.1 – use ‘ignore_sticky_posts’ with a boolean argument instead. ‘exclude’ is not a query argument so WordPress ignores it. Post exclusion via query is done using the key ‘post__not_in’ with a single post ID or array of IDs instead. However as @vancoder points out, the argument … Read more

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