Compare meta key to current date in pre get post

What you’re trying isn’t possible with WP_Query. The reason is that because you have only stored the duration, it’s not possible to tell whether a post has expired until you know the publication date and the duration time and add them together. That’s what this does: $expire = get_field( ‘status_time_duration’ ) + get_the_time( ‘U’ ); … Read more

How to use pre_get_posts

pre_get_posts happens just before a WP_Query needs to go to the database to grab stuff. Since every page has a main query, that can be changed. Does it go in the search template? No! By the time templates are loaded, the main query has already decided what to grab and gone to the database. Newcomers … Read more

Can a link in WordPress contain a query string that is picked up as $_POST

Looking at the pre_get_posts hook, the problem becomes apparent, the $Format variable is being pulled out of thin air: function get_all_terms($query) { if(empty($Format)) $Format=”test 1″; echo $Format; This variable is undefined, you cannot declare a variable in one file then use it in in other places like this. To do that you have to declare … Read more

Prevent A Specific Custom Post Type Showing In WP Search Results Page

Instead of enumerating page IDs you don’t want, you could instead set the post types that you do want. You can of course combine the 2 approaches if you wish, but below I’ve included pages, posts, and another type you might want if you have other types on your site. e.g.: function tp_remove_pages( $query ) … Read more

CPT is simply not displayed in the main archive with “pre_get_posts”

Okay, this is what works for me, thanks to the friendly hint of Jacob Peattie: function include_custom_post_type_archives($query) { if (is_home() && empty($query->query_vars[‘suppress_filters’])) { $query->set(‘post_type’, array( ‘post’, ‘landingpages’, )); return $query; } } add_filter(‘pre_get_posts’, ‘include_custom_post_type_archives’);

Override tax_query with pre_get_posts to include other term_ids on a single category

but now it seems, I have two tax_queries, one is in WP_Query->query_vars and the other is just in WP_Query That is normal. WP_Query::$query_vars is an array of query vars merged with the default ones for WP_Query. So if you do $query = new WP_Query( array( ‘post_status’ => ‘publish’ ) ) (or $query = new WP_Query( … Read more