WP Query – Is this correct?

I am guessing but based on your choice of placeholder names in the code above… $args = array( ‘meta_key’ => ‘myvalue’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’ ); … your meta_key argument is wrong. That is the meta key not the meta value as your naming convention suggests. meta_key (string) – Custom field key. http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters … Read more

number of posts per page + random + exclude categories

pre_get_posts in your child themes functions file is the best in my opinion. add_action( ‘pre_get_posts’, ‘wpsites_custom_get_posts’ ); function wpsites_custom_get_posts( $query ) { if( $query->is_main_query() && $query->is_home() ) { $query->set( ‘cat’, ‘-182,-184’ ); $query->set( ‘posts_per_page’, ’12’ ); $query->set( ‘orderby’, ‘RAND’ ); } } This method is more flexible in my opinion.

Proper syntax to add boolean in array()

Your code fails because: array( ‘cat’ => -9, -4 ); is the same as: array( ‘cat’ => -9, -4 ); The -4 is its own element, not a part of the ‘cat’ argument. The correct way to do what you tried to do would be: array ( ‘cat’ => array( -9, -4 ) ); But … Read more

Nested WP_Query breaking loop

This can be done in a single query: $parent_only = new WP_Query( array( ‘post_parent’ => 0, ) ); If you want to have all children of a specific page (for e.g.) in the loop (or on a request that returns TRUE for is_singular()), use get_the_ID() as argument for post_parent. Edit (after seeing the full loop … Read more

post_parent array doesn’t work

It’s not recommended to use query_posts(), check for example this warning note in the Codex: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by … Read more

Wrong post title displayed from loop

Welcome the the WordPress Stack Exchange and congrats on your first post! First off, you may not want to use query_posts() here. Second off – the_post() needs to be before the_title() as it sets up all the posts functions such as the_title(), the_permalink() etc. and queues the next post in your while loop. Your Loop … Read more

Exclude first post (sticky or not) from the loop using query_posts()

You shouldn’t really need to “exclude” anything. Just make use of the built in loop tracking. WP_Query will “remember” where you left off. For example: if (have_posts()) { while (have_posts()) { the_post(); echo ‘firstpost##’; the_content(); echo ‘##endfirstpost’; break; } } // do some other stuff if (have_posts()) { while (have_posts()) { the_post(); echo ‘otherposts##’; the_content(); … Read more

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