Problem with ‘post__not_in’

You are trying to supply an array as part of the string query parameter. You could instead just supply the arguments list as an array like this: $newQuery = new WP_Query( array( ‘posts_per_page’ => 5, ‘orderby’ => ‘rand’, ‘cat’ => $cats[0]->term_id, ‘post__not_in’ => array($exclude_post) ) );

WP_Query by Category Name

category is a valid parameter for get_posts, not for WP_Query. Here are the valid category parameters for WP_Query cat (int) – use category id. category_name (string)– use category slug (NOT name). category__and (array) – use category id. category__in (array) – use category id. category__not_in (array) – use category id. You can use either use cat … Read more

Is ‘no_found_rows’ a silver bullet for WP_Query optimization when getting all posts of a certain type?

Your code will run five SQL queries in total. When setting no_found_rows => true the first two queries SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.ID IN (1,49,63,249,72,95,259,207,183,225) AND wp_posts.post_type=”post” AND (wp_posts.post_status=”publish”) ORDER BY wp_posts.post_date ASC LIMIT 0, 10 SELECT FOUND_ROWS() will become a single query like SELECT wp_posts.ID FROM wp_posts WHERE 1=1 AND … Read more

WP_Query pulling an extra post per page

Sticky posts do add to the post count rather than being included in it. You can alter your query to ignore sticky posts though. $allposts = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 20, ‘ignore_sticky_posts’ => true ); But you are also missing pagination parameters. $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $allposts = array( ‘post_type’ … Read more

How to query posts of standard post format. For real

It looks like your syntax is a little off for the tax query. Try this: $query = new WP_Query( array( ‘post_type’ => ‘post’, ‘cat’ => ‘-1’, ‘posts_per_page’ => 2, ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_format’, ‘field’ => ‘slug’, ‘terms’ => array(‘post-format-aside’, ‘post-format-gallery’, ‘post-format-link’, ‘post-format-image’, ‘post-format-quote’, ‘post-format-status’, ‘post-format-audio’, ‘post-format-chat’, ‘post-format-video’), ‘operator’ => ‘NOT IN’ ) … Read more

How do I exclude all images from a wp_query?

Pretty much the solution is to include all mimes except images. WordPress has a nifty little function where it keeps all it’s accepted mime-types called get_allowed_mime_types() ( cleverly named ) which returns an Array() of mimes. All we need to do is get the difference between the returned array and the array of mime-types we … Read more

Extending WP_Query — Optimise SQL query

Here’s an idea, however it will require the ability to make custom SQL queries – with $wpdb. Since you want to get posts followed by a user, you can create a view, with the following structure: id user_id post_id post_title post_content … (all other post fields) don’t worry about duplicating posts. When you select, you … Read more

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