SQL Statement generated by WP_Query not producing expected results

It looks like this section: AND (wptom_posts.post_status=”publish” OR wptom_posts.post_author = 1 AND wptom_posts.post_status=”private”) is not tied in at all to the two different query conditions… Perhaps the original code should be three conditions for part 1: array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘operator’ => ‘IN’), array( ‘taxonomy’ => ‘post_tag’, ‘field’ … Read more

Multiple orderby parameters in pre_get_posts() action

Never forget that there’re actually two filters // Add additional query args that are allowed by the API by default pre_get_posts // Modify the query herself posts_clauses // Inspect the resulting string – test this one in for e.g. phpMyAdmin posts_request So everything you can achieve using the pre_get_posts filter should be done there. The … Read more

Varying the number of posts per page from the first one

Thanks to s_ha_dum for the tip. I managed to solve it by setting the offset parameter in the special case of 2nd page onwards for the front page as follows: function limit_posts_per_home_page() { $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $first_page_limit = 5; $limit = get_option(‘posts_per_page’); if (is_front_page()) { if ($paged == 1) { $limit … Read more

How pre_get_posts filter by roles in WP Admin

I’d make 2 queries. This would look something like this : function add_role_filter_to_posts_administration(){ //execute only on the ‘post’ content type global $post_type; if($post_type == ‘post’){ $user_role=””; // Get all user roles $user_roles = array(); foreach ( get_editable_roles() as $key => $values ) : $user_roles[ $key ] = $values[‘name’]; endforeach; // Set a selected user role … Read more

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