Perform query with meta_value date

I did something similar, the technique you need to use is called a meta query. Here is the query I wrote to get posts based on a date value stored as a custom field meta value. query_posts( array( ‘post_type’=>’post’, ‘order’=>’ASC’, ‘orderby’=>’meta_value_num’, ‘meta_key’=>’date_event’, ‘posts_per_page’=> -1, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘date_event’, ‘value’ … Read more

Query by one meta_key and sort by another (possibly NULL value)

I don’t think there’s a way to do it without using filters. Using posts_clauses you could do: function wpse163696_posts_clauses( $pieces, $query ) { if ( $query->get( ‘orderby’ ) != ‘dealer_date’ ) { return $pieces; } global $wpdb; $order = $query->get( ‘order’ ); $pieces[ ‘join’ ] .= $wpdb->prepare( ‘ LEFT JOIN ‘ . $wpdb->postmeta . ‘ … Read more

Disable slow media queries?

Solution for WordPress versions >= 4.7.4 (4.8) Ticket #31071 introduces patches with new filters to override three possible slow media queries, in the wp_enqueue_media() function: media_library_show_audio_playlist (@param bool|null) From the inline doc: Whether to show the button, or null to decide based on whether any audio files exist in the media library. media_library_show_video_playlist (@param bool|null) … Read more

Identify which loop you are hooking into; primary or secondary?

Just a quick update that a new method is_main_query() has been introduced in WP 3.3. Example: add_action( ‘pre_get_posts’, ‘foo_modify_query_exclude_category’ ); function foo_modify_query_exclude_category( $query ) { if ( $query->is_main_query() && ! $query->get( ‘cat’ ) ) $query->set( ‘cat’, ‘-5’ ); } Resources: WPDevel: New API in 3.3: is_main_query() Codex reference: is_main_query() Related Trac Ticket #18677

Alter query on edit.php

Few days ago I wrote a quick solution using pre_get_posts filter to hide some pages in admin area. Maybe you could use it as a good starting point for whatever you’d like to achieve. if ( is_admin() ) add_filter(‘pre_get_posts’, ‘mau_filter_admin_pages’); function mau_filter_admin_pages($query) { $query->set(‘post__not_in’, array(1,2,3) ); // Do not display posts with IDs 1, 2 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)