Exclude a WordPress post from pre_get_posts if a field is null

@Howdy_McGee – Thanks for pointing me in the right direction. Below is the code I used. By the way, I know that the FacetWP plugin can be a little particular with queries. In case anyone is wondering, this works with it. function set_posts_per_page_for_attorneys_cpt( $atty ) { if ( !is_admin() && $atty->is_main_query() && is_post_type_archive( ‘attorneys’ ) … Read more

Archive by custom post type and custom date field

Thanks to Milo for helping me through this. Here is the code that worked for me. function custom_events_query( $query ) { if ( $query->is_main_query() && $query->is_archive && !is_admin()&& is_post_type_archive(‘events’) && $query->query_vars[‘m’]!=”) { $query->set( ‘post_type’, ‘events’ ); $query->set( ‘meta_key’, ‘event_date’ ); $query->set( ‘orderby’, ‘meta_value’ ); $query->set( ‘order’, ‘DESC’ ); $query->set( ‘post_per_page’, 10 ); unset($query->query_vars[‘year’]); unset($query->query_vars[‘monthnum’]); unset($query->query_vars[‘day’]); … Read more

pre_get_posts and the blog page

Your blog page is actually your home page, so you need to use is_home(). For the static frontpage, is_front_page() would be used EDIT Sorry for being confusing :-). This how it works when a static frontpage is set The page set as your frontpage is actaully just a cover page. When you think of a … Read more

Date Query to Pull Current and Future Posts

I wonder if you mean this kind of date_query: $query->set( ‘date_query’, [ [ ‘after’ => ‘today midnight’, ‘column’ => ‘post_date_gmt’, ‘inclusive’ => true, ], ] ); where we use the after attribute. Here the after date will be calculated by WP_Date_Query as: gmdate( ‘Y-m-d H:i:s’, strtotime( ‘today midnight’, current_time( ‘timestamp’ ) ) ); With the … Read more