Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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;
share|improve this answer
    
tx , i'm going with SELECT * FROM $wpdb->posts WHERE 1=0; –  user416096 Apr 9 '12 at 13:28
    
@user416096 don't forget to accept an answer. –  soulseekah Apr 9 '12 at 22:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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