How to use offset in WP_Query

Where do I put the offset function?

        ?php
            $args = array(
                'post_type' = 'post',
                'category_name' = 'category',
                'orderby' = 'date',
                'order' = 'DESC',
                'showposts' = 4);

            $wp_query = new WP_Query($args);
            if($wp_query-have_posts()) :
            while($wp_query-have_posts()) :
            $wp_query-the_post(); ?

Topic offsets loop wp-query Wordpress

Category Web


offset is one of the arguments that you can pass to WP_Query, so it belongs in the $args array:

$args = array(
    'post_type'     => 'post',
    'category_name' => 'category',
    'orderby'       => 'date',
    'order'         => 'DESC',
    'showposts'     => 4,
    'offset'        => 4,
);

PS: $wp_query is a reserved variable used by the main query. When creating your own WP_Query instance you should use a different variable name.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.