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

How to do a query only on a specific admin page?

It’s worthwhile pointing out that using admin_init within the current_screen filter is too late because admin_init has already fired. Instead do: add_action(‘current_screen’, ‘current_screen_callback’); function current_screen_callback($screen) { if( is_object($screen) && $screen->id === ‘top_level_custom-settings-api’ ) { add_filter(‘top_level_screen’, ‘__return_true’); } } Elsewhere in your top_level_page_callback callback responsible for executing the query: function top_level_page_callback() { $active_posts = null; if … Read more

WP_Query with LIKE in meta gives strange query

No, you’re doing everything right and this should actually work as those placeholders are removed at a later point before actually executing the query. This is part of a security measure introduced with WordPress 4.8.3. Quoting from the corresponding developer note: As part of the WordPress 4.8.3 release, there is a change in esc_sql() behaviour … Read more

How to get previous 10 days post from a specific date – WP Query

Yes, it is possible. You can pass full date as before and after params, so: $given_date_as_time = strtotime(‘2017-11-22 00:00:00’); $args = array( ‘post_type’ => ‘post’, ‘date_query’ => array( ‘before’ => date( ‘c’, $given_date_as_time ), ‘after’ => date(‘c’, strtotime( ‘- 10 days’, $given_date_as_time ) ), ), ); $query = new WP_Query( $args ); above query is … Read more

Query certain amount of posts from multiple dates

You’re just about there. Each date_query array represents a separate condition to filter by. By default, these are combined using AND which limits the scope further. In your case, you want to change the relation to OR and then add the different years as their own separate conditions in the array. $args = array( ‘date_query’ … Read more

Order by two meta keys

I’m not 100% certain what specific order you’re asking for, but you just need to assign an associative array to the ‘orderby’ value. Here’s an example: $args = array( ‘post_type’ => ‘brands’, ‘meta_query’ => array( array( ‘key’ => ‘br_type’, ‘value’ => ‘Aviation’ ), array( ‘key’ => ‘br_category’ ), array( ‘key’ => ‘br_name’ ) ), ‘posts_per_page’ … Read more