- // Fires after the query variable object is created, but before the actual query is run. https://developer.wordpress.org/reference/hooks/pre_get_posts/
- /*
- * Exclude Posts if option is set to `hide`
- */
- function modify_default_queries($query) {
- if ( !is_admin() ) {
- if ( $query->is_home() || $query->is_archive() ) {
- $meta_query = [
- 'relation' => 'OR',
- 'key' => 'hide_post-in-view-cats',
- 'value' => true,
- 'compare' => '!=',
- ),
- 'key' => 'hide_post-in-view-cats',
- 'compare' => 'NOT EXISTS'
- )
- ];
- $query->set( 'meta_query', $meta_query );
- }
- return $query;
- }
- }
- add_action( 'pre_get_posts', 'modify_default_queries' );
Recent Pastes