Display posts from a category

You’re doing query_posts and then immediately get_posts. This looks wrong. Remove the query_posts call. Also, where does your $cat come from? It doesn’t appear to be set anywhere in your code snippet. Try to start with setting it first: $cat = get_query_var(‘cat’);

Query posts by Author and/or by Tag

Your first query is very strange. You seem to be mixing meta_query parameters with other WP_Query arguments. You can’t do that. author is not a valid component of a meta_query, neither is tag. The correct meta_query, if I am interpreting this right, wouldn’t even be a meta query. You are dealing with a taxonomy, a … Read more

How to exclude Sticky from Recent Post?

You can try this: $args = array( ‘post__not_in’ => get_option( ‘sticky_posts’ ), ‘posts_per_page’ => 5, ); $recent = new WP_Query( $args ); to exclude the sticky posts. You can read more about it here in the Codex.

How to show one post different from the rest?

The code you posted will only make difference in adding <div class=”first-post”></div> for the first post, so it still displays same information for all posts. Try this instead: <?php $queryObject = new Wp_Query( array( ‘showposts’ => 5, ‘post_type’ => array(‘post’), ‘category_name’ => videos, ‘orderby’ => 1, )); // The Loop if ( $queryObject->have_posts() ) : … Read more

why the same code got different results when using query_posts in functions.php and index.php

In your first code example, you hook into the pre_get_posts action, which fires during the main query. But instead of manipulating that query, you trigger another one using query_posts(), which fires the hook again, and you end up with an infinite loop. With the second code example, you’re just overriding the main query after it’s … Read more

Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months

First of all I don’t think you should use your custom query_posts in here. WordPress already queries posts on archive pages, so it’s waste of time to query them one more time. You should be using pre_get_posts filter. function my_pre_get_posts($query) { if (!is_admin() && is_main_query() ‘<YOUR_POST_TYPE>’ === $query->query_vars(‘post_type’) && $query->is_archive()) { $query->set(‘orderby’,’meta_value’); $query->set(‘meta_key’, ‘<YOUR_POST_TYPE>’); //formatted … Read more