Multiple orderby parameters in pre_get_posts() action

Never forget that there’re actually two filters // Add additional query args that are allowed by the API by default pre_get_posts // Modify the query herself posts_clauses // Inspect the resulting string – test this one in for e.g. phpMyAdmin posts_request So everything you can achieve using the pre_get_posts filter should be done there. The … Read more

WP Cron and wp_insert_post

For those who stumble upon this later, use either option 1 or 2 found here: https://core.trac.wordpress.org/ticket/19373. “For other developers who run into this and need to work around it, either of these 2 options work: call wp_set_post_terms() to add your taxonomies after calling wp_insert_post() set up a “current user” in your script before calling wp_insert_post()”

Ignore a filter on the media library

You can use is_admin() in conjunction with the admin global variable $pagenow to make sure you’re not on either the upload or media page: function remove_images( $where ) { global $wpdb, $pagenow; if( is_admin() && in_array( $pagenow, array( ‘upload.php’, ‘media-upload.php’ ) ) { return $where } $where .= ” AND {$wpdb->posts}.post_mime_type NOT LIKE ‘image/%'”; return … Read more

Meta Query with date and time on the same Day before given time

Found the error: $args = array( “posts_per_page” => 12, “paged” => $paged, “post_type” => array( “event”, “post” ) , “post_status” => “publish”, “meta_key” => “_thumbnail_id”, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘event_start’, ‘value’ => date(“Y-m-d H:i:s”) , ‘compare’ => ‘>=’, ‘type’ => ‘DATETIME’ ) , array( ‘key’ => ‘event_start’, ‘compare’ => ‘NOT … Read more