query_posts and only show results if a custom field is not empty

Try this code: $args = array( ‘posts_per_page’ => ’10’, ‘post_type’ => ‘programmes’, ‘meta_key’ => ‘popularityfig’, ‘meta_value’ => ”, ‘meta_compare’ => ‘!=’, ‘order’ => ‘DESC’ ); There’re 2 arguments you might want to note in the code: meta_value and meta_compare. Using meta_compare with operator != will exclude posts with empty meta value.

How to display posts by current user/author in a custom page template?

this should work for you: if ( is_user_logged_in() ): global $current_user; wp_get_current_user(); $author_query = array(‘posts_per_page’ => ‘-1′,’author’ => $current_user->ID); $author_posts = new WP_Query($author_query); while($author_posts->have_posts()) : $author_posts->the_post(); ?> <a href=”https://wordpress.stackexchange.com/questions/23829/<?php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a> <?php endwhile; else : echo “not logged in”; endif;

Is `query_posts` really slower than secondary query?

You ask: is query_posts really slower than some secondary query… The fact is that if you’re calling query_posts() from a theme then it already is a secondary query. WordPress has already queried the database once to get a certain page then it hits your query_posts() function and queries the database again creating a second query … Read more

Using categories & “stickyness” together

Just add ‘post__in’ => get_option(‘sticky_posts’) to your query, to confine your query to only sticky posts. So, $getHighlights = array( ‘numberposts’ => 7, ‘post_type’ => array(‘post’,’Event’), ‘post__in’ => get_option(‘sticky_posts’), ‘category_name’ => ‘Highlights’ ); should work for you. Edit: This is how you can merge two arrays to get the sticky posts at the top of … Read more

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) ) );

Display content from a specific category

The argument isn’t category, it is cat. Your query fails because you are using an argument that doesn’t exist. $args = array( ‘post_type’ => ‘post’ , ‘orderby’ => ‘date’ , ‘order’ => ‘DESC’ , ‘posts_per_page’ => 6, ‘cat’ => ‘3’, ‘paged’ => get_query_var(‘paged’), ‘post_parent’ => $parent ); $q = new WP_Query($args); if ( $q->have_posts() ) … Read more

Query posts: how to exclude results if post is in multiple categories

This is probably not a “pure” way to do it, but this code make an array of featured post ids and then excludes them from future get_posts. $featuredPosts = get_posts(‘category’=>’D’,’numberposts’=>’-1′); $fPId = array(); foreach ($featuredPost as $currentPost) { array_push($fPId,$currentPost->ID); } $aPosts = get_posts(‘category’ => ‘a’, ‘exclude’=>$fpId); $bPosts = get_posts(‘category’ => ‘b’, ‘exclude’=>$fpId); $cPosts = get_posts(‘category’ … Read more

Build a content and excerpt grid loop with paging and options for # of posts

The $wp_query properties allow “alot” Actually it’s not that hard if you use parts of the $wp_query object like current_post. Here you can see some examples that make some tricky use of things like is_paged(), $wp_query->current_post and $wp_query->posts_per_page. You can switch MarkUp depending on if you’re on the first or later pages, if you got … Read more

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