Limiting query_posts to 1, regardless of sticky post?

$GLOBALS[‘wp_query’]->found_posts will give you the number of posts. $GLOBALS[‘wp_query’]->posts is an array with all the posts found. So instead of while ( have_posts() ) : the_post(); use: setup_postdata( $GLOBALS[‘wp_query’]->posts[0] ); get_template_part( ‘content’, ‘super’ ); This way you don’t run through all post, you really just use one. And please read When should you use WP_Query … Read more

query_posts() in function makes global $wp_query out of sync?

Update with a better example header( ‘Content-Type: text/plain;charset=utf-8’ ); error_reporting( E_ALL | E_STRICT ); function failed_unset() { // Copy the variable to the local namespace. global $foo; // Change the value. $foo = 2; // Remove the variable. unset ( $foo ); } function successful_unset() { // Remove the global variable unset ( $GLOBALS[‘foo’] ); … Read more

Modify main WordPress loop with a parse_query filter

Ultimately all meta queries get run through _get_meta_sql. wp-includes/meta.php Line 402 – 403 in the _get_meta_sql function The following coditional statement runs for any meta queries. if ( empty( $meta_key ) && empty( $meta_value ) ) continue; There’s a ticket here for this which outlines what we should be able to do. http://core.trac.wordpress.org/ticket/16735 What you … Read more

Get posts by menu ID

I recently needed the same thing, I had menu of categories and I needed to get the categories that in the menu. After a several hours digging in the WP core, I found the wp_get_nav_menu_items() function that helped me. I finnally came with this, 220 was my menu_id $navcat = wp_get_nav_menu_items(‘220’); foreach ($navcat as $obj) … Read more

Determine if more posts are available than was asked for in `query_posts()`?

First of all: do not use query_post! For more information read: When should you use WP_Query vs query_posts() vs get_posts()? Use the WP_Query class to fetch your products, also pay attention that the showposts argument is deprecated, use posts_per_page instead: $args = array( ‘post_type’ => ‘product’, ‘taxonomy’ => ‘product_cat’, ‘term’ => $idObj->slug, // category slug … Read more

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