Created
June 25, 2020 21:49
-
-
Save wpjess/59639f5d7e32ae47ab74d8f93958ae55 to your computer and use it in GitHub Desktop.
Apply query var to a targeted query automatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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