Skip to content

Instantly share code, notes, and snippets.

@wplit
Last active April 11, 2020 23:24
Show Gist options
  • Select an option

  • Save wplit/f2e00c6e4ebcb0e411a617e484ad2a4e to your computer and use it in GitHub Desktop.

Select an option

Save wplit/f2e00c6e4ebcb0e411a617e484ad2a4e to your computer and use it in GitHub Desktop.
add offset to post category
add_action( 'pre_get_posts', 'lit_offset_category_filter' );
function lit_offset_category_filter($query) {
if ( ! is_admin() && $query->is_main_query() ) { // Apply to main WP query
if( $query->is_category()) { // Only on category pages
$offset = '3'; // Number of posts to offset
$query->set( 'offset', $offset );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment