Skip to content

Instantly share code, notes, and snippets.

@sinebeef
Last active June 4, 2019 00:02
Show Gist options
  • Save sinebeef/0e682f0a42ee7cd8ee8041ac8d802ed5 to your computer and use it in GitHub Desktop.
Save sinebeef/0e682f0a42ee7cd8ee8041ac8d802ed5 to your computer and use it in GitHub Desktop.
WP Modify pre_get_posts
/* Modify $query via pre_get_posts to change sorting
* of certain archive pages.
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
*/
add_action( 'pre_get_posts', 'custom_query_vars' );
function custom_query_vars( $query ) {
if ( !is_admin() && $query->is_main_query() ) {
if ( is_product_category('cleats') ) {
$query->set( 'posts_per_page', '-1' );
}
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment