When to use WP_query(), query_posts() and pre_get_posts

You are right to say: Never use query_posts anymore pre_get_posts pre_get_posts is a filter, for altering any query. It is most often used to alter only the ‘main query’: add_action(‘pre_get_posts’,’wpse50761_alter_query’); function wpse50761_alter_query($query){ if( $query->is_main_query() ){ //Do something to main query } } (I would also check that is_admin() returns false – though this may be … Read more

why same category base and single post base don’t work?

When you set WordPress up with: The set-up Custom Permalink Structure: /blog/%postname%/ Category base: blog Generated rewrite rules WordPress generates these rewrite rules: blog/([^/]+)(?:/([0-9]+))?/?$ => index.php?name=$matches[1]&page=$matches[2] blog/(.+?)/?$ => index.php?category_name=$matches[1] Rewrite rule position in the rewrite_rules_array Your post rewrite rule (#1) is positioned earlier (therefore higher priority) than the category rewrite rule (#2) in your rewrite_rules_array. … Read more

posts_per_page showing 16 elements instead of 3

Your query might be picking up sticky posts. To ignore them, try this: $args = array( ‘meta_query’ => array( array( ‘key’ => ‘featured_posts’, ‘compare’ => ‘==’, ‘value’ => ‘0’ ) ), ‘post_type’ => ‘post’, // Changed ‘3’ to 3, since WP_Query expects an int. ‘posts_per_page’ => 3, // Ignore the sticky posts. ‘ignore_sticky_posts’ => true, … Read more

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