Exclude current post from an array of posts?

Use array_diff() to remove the current post ID from an array of other post IDs. $include = array( 17, 111, 108, 158); $include = array_diff( $include, array( $post->ID ) ); $args = array( ‘post__in’ => $include ); $posts = new WP_Query( $args ); Edit to include a point raised by Pieter Goosen–If $include is not … Read more

Include posts from some categories while excluding from others

You could use a Taxonomy Query, like so: $args = array( ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘terms’ => array(), ‘operator’ => ‘IN’ ), array( ‘taxonomy’ => ‘category’, ‘terms’ => array(), ‘operator’ => ‘NOT IN’, ), ), ); $query = new WP_Query( $args ); This will query posts that are in … Read more

wp_list_pages() exclude category

I think the solution that would work out best for you is just using your own query. Since you have modified pages to have categories and tags taxonomies wp_list_pages doesn’t support excluding the arguments quite like that. You could get an array of all page IDs that are assigned to each category, but you’d be … Read more

2 wordpress loops showing 1 post from same post type – how to avoid showing the same post?

Your two queries are identical, meaning you only need one of them. The basic solution is: global $testimonials; $testimonials = new WP_Query(array( ‘posts_per_page’ => 2, /* <– get both */ ‘post_type’ => ‘testimonial’, ‘post_status’ => ‘published’, ‘orderby’ => ‘rand’, ‘ignore_sticky_posts’ => true /* you need this to control post count accurately */ )); // header … Read more

Excluding posts not working

Have a look at https://codex.wordpress.org/Class_Reference/WP_Query, and maybe try passing your args in an array. Above page lists this exact example, which should work: // This WILL work $exclude_ids = array( 1, 2, 3 ); $query = new WP_Query( array( ‘post__not_in’ => $exclude_ids ) );

Multiple arrays in post__not_in parameter

No, it doesn’t. You’d just merge the arrays: ‘post__not_in’ => array( array_merge( get_option( ‘sticky_posts’ ), array( 1, 2, 3 ) ), ) And just because someone else will mention it if I don’t: post__not_in has terrible performance and you’d be better off finding an alternate solution.

Exclude post format from get_posts

You just need to set the operator parameter to ‘NOT IN’ (see Codex on tax queries). Untested, but for your purposes: $args = array( ‘post_type’=> ‘post’, ‘post_status’ => ‘publish’, ‘order’ => ‘DESC’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_format’, ‘field’ => ‘slug’, ‘terms’ => array( ‘post-format-aside’ ), ‘operator’ => ‘NOT IN’ ) ) );

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