Exclude a category of posts in author template

Never use query_posts, use pre_get_posts to modify any main query. function wpd_exclude_author_category( $query ) { if ( $query->is_author() && $query->is_main_query() ) { $query->set( ‘category__not_in’, array( 42 ) ); } } add_action( ‘pre_get_posts’, ‘wpd_exclude_author_category’ );

Echo the number of posts being displayed

rearrange your code and use post_count; example: <?php $movieNumber = 1; $today = date(‘Ymd’); $posts = array ( ‘post_type’ => ‘movie’, ‘posts_per_page’ => -1, ); $loop = new WP_Query( $posts ); ?> <div id=”posters<?php echo $loop->post_count; ?>”> <?php while ( $loop->have_posts() ) : $loop->the_post(); …etc…

Custom post query error

get_posts() doesn’t accept posts as input, it only takes argument to query posts. So it’s useless and breaking step in your process. It should work if you throw get_posts() out. See Displaying Posts Using a Custom Select Query in Codex for extensive writeup on custom queries. PS your query is seriously insecure, you need to … Read more

Get postlist for each category using query_posts?

Your use of queries is completely wrong, and as stated before, query_posts should never be used. The method you are using to retrieve you category ID’s are also a waste of resources. It would save much more if you knew the ID’s. I would also look at get_categories to retrieve my category details and passing … Read more

limit number of post for achive page

You should use the pre_get_posts filter for this. For example, you could do this in your theme’s functions.php file: function limit_category_posts( $query ) { if ( $query->is_archive() ) { // Do not do this for the date or category archives. if ( $query->is_date() || $query->is_category() ) return $query; if ( $query->query_vars[‘cat’] == 8 ) { … Read more

Query all post types but limit to parents

In your functions.php you can create a function that will hook into the pre_get_posts hook. Something like (just an example): function alter_query($query){ $query->set(‘post_parent’, 0); } add_action( ‘pre_get_posts’, ‘alter_query’ ); There you can alter the main query. That way while(have_posts()) : the_post(); will still just normally work. (You should check if you are altering the right … Read more