How to calculate post index when using offset in custom query

In your case, count would be offset + current_post: $my_query = new WP_Query( array( ‘post_type’ => ‘colors’, ‘posts_per_page’ => 5, ‘offset’ => 2 ) ); if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post(); echo $my_query->query_vars[‘offset’] + $my_query->current_post; the_title(); endwhile; endif; wp_reset_postdata();

AJAX Breaking Offset Argument In WP Query

So I’m guessing this is a follow-up to this question. And based on my answer there, you can use/add the offset parameter like so: In category.php, just set the preferred offset: $the_query = new WP_Query( array( ‘category__in’ => array( $cat_id ), ‘post_type’ => ‘post’, ‘posts_per_page’ => 5, ‘paged’ => $current_page, ‘offset’ => 1, // set … Read more

Apply query arguments after the nth post

Sure! There are tons of parameters for WP-Query that can probably do what you want. Offset is usually used when your data is ordered. So if you want to ignore the two most recent ones you need to order it by date descending first, then set offset = 2. It doesn’t matter if you apply … Read more

Stomping WP_Query in author archive to facilitate pagination with custom queries

t31os says: [See edit history for previous code and comments] Using Ajax to paginate your queries I’ve put together some code that will fetch your posts and comments via ajax using simple prev/next navigation via ajax. 1) Replace all the code you posted in your author.php with the following.. <?php $cat_settings = array( ‘Articles’ => … Read more

Loop Offset for tag based “Related Posts”

doing 3 separate queries is unnecessary and inefficient, do one query for all 12 posts and output your container markup every fourth post. $args = array( ‘tag__in’ => $tag_ids, ‘post__not_in’ => array($post->ID), ‘posts_per_page’=> 12 ); $my_query = new WP_Query( $args ); if( $my_query->have_posts() ): ?> <div class=”container”> <?php while ( $my_query->have_posts() ) : $my_query->the_post(); the_title(); … Read more

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