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

wp_dropdown_categories with multiple select

wp_dropdown_categories has a filter applied to the output that is called right before the function returns or echos the output. With this you can add a filter to your funtions.php file that manipulates the select field and adds a multiple attribute to it. The filter below would search for the select opening tag and add … Read more

Compare two numeric custom fields

I think something like this, but not tested, and my SQL-foo is rather weak: $test = $wpdb->get_col( $wpdb->prepare( ” SELECT DISTINCT $wpdb->posts.* FROM $wpdb->posts INNER JOIN $wpdb->postmeta AS mt1 ON ( wp_posts.ID = $wpdb->postmeta.post_id ) WHERE $wpdb->postmeta.meta_key = ‘goals-made’ AND( mt1.meta_key = ‘goals-against’ AND CAST($wpdb->postmeta.meta_value AS INT) > CAST(mt1.meta_value AS INT) ) ” )); This … Read more

Remove [gallery] shortcode altogether

The short code is actually entered into then page or post content so disabling the short code processing prevents the gallery short code from being replaced with the gallery images but it doesn’t affect the post content. The best solution is to add a new short code handler after removing the default gallery handles. Another … Read more

Multipart/formatted MySQL query problem

After much trial and error I finally figured out a solution using mysqli. I consider it a acceptable solution since the query will only be run on plugin updates. $mysqli = new mysqli(); $mysqli->connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql = ” DROP TRIGGER IF EXISTS {$wpdb->get_blog_prefix($site->id)}post_queue_insert; CREATE TRIGGER {$wpdb->get_blog_prefix($site->id)}post_queue_insert BEFORE INSERT ON {$wpdb->get_blog_prefix($site->id)}posts FOR EACH ROW … Read more

Slow wp_enqueue_media()

To load admin scripts only on your pages, you should use the $hook-parameter: function enqueue_scripts( $hook ) { if( ‘my-page’ != $hook ) return; wp_enqueue_script(‘jquery’); wp_enqueue_media(); // etc… } add_action(‘admin_enqueue_scripts’, ‘enqueue_scripts’); Concerning the loading problem. This seems to be still an open problem. The ticket 27985 was followed up by #32264, which is not closed … Read more

Custom query_var causes displaying posts archive on front page

After detailed debugging of WP::parse_request() and WP_Query::parse_query() I found out that unset( $query_vars[‘date’] ); in ‘request’ filter helps. It basically unsets date query var before WP_Query::parse_query() is invoked so is_home() returns false. add_filter( ‘request’, function( $query_vars ) { global $wp_query, $wp; if ( ! $wp_query->is_main_query() ) { return $query_vars; } $qv_keys = array_keys( $wp->query_vars ); … Read more