0

i want to remove a certain query in wp 3.1

add_filter( 'query', 'remove_delete_7_day_draft_queries' ); 

function remove_delete_7_day_draft_queries( $query ) { 
    global $wpdb;
    $q = "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date";
    if ( $q == $query) {
        return false;
    }

    return $query; 
}

but in the error log i see something like this: WordPress database error Query was empty for query made by get_default_post_to_edit

any ideea how to remove the execution of the query without any error ? tx

1

I'm assuming you're talking about this piece of maintenance code right here:

http://core.trac.wordpress.org/browser/tags/3.3.1/wp-admin/includes/post.php#L419

Indeed, the code calls on lower level functionality of $wpdb, which doesn't contain too many hooks, only one in fact, query.

http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/wp-db.php#L1061

So, in order to return an empty result set you'll have to come up with a no-operation type of query, here are some examples:

  • SELECT NULL; (returns 1 NULL result)
  • DO 0;
  • SET @ignore_me = 0;
  • SELECT * FROM `$wpdb->posts` WHERE 1=0;
1
  • tx , i'm going with SELECT * FROM $wpdb->posts WHERE 1=0;
    – user416096
    Apr 9 '12 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.