Skip to content

Instantly share code, notes, and snippets.

@wpjess
Created June 25, 2020 21:49
Show Gist options
  • Save wpjess/59639f5d7e32ae47ab74d8f93958ae55 to your computer and use it in GitHub Desktop.
Save wpjess/59639f5d7e32ae47ab74d8f93958ae55 to your computer and use it in GitHub Desktop.
Apply query var to a targeted query automatically
// APPLY QUERY VAR TO SPECIFIC QUERY AUTOMATICALLY
function jess_apply_filter_automatically($query) {
if ( is_front_page() && in_array ( $query->get('post_type'), array('events') ) ) {
$query->set('jess_random_posts', 3);
$query->set('posts_per_page', -1);
}
}
add_action( 'pre_get_posts', 'jess_apply_filter_automatically' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment