WordPress.org

Ready to get started?Download WordPress

Forums

WP Db Abstraction
[resolved] LIMIT fix for excluding categories (2 posts)

  1. markegli
    Member
    Posted 1 year ago #

    I thought it worth making a note here: I was having trouble where a category wasn't properly excluded when doing a query such as $custom_query = new WP_Query('cat=-5') against SQL Server 2005. I tracked the problem down to the way LIMIT is changed into TOP in translations.php. The limit was being applied to the sub-query in the NOT IN statement as well as the main query. A simple change on line 707 of translations.php fixed the problem.

    Original:

    $query = str_ireplace('DELETE ', 'DELETE TOP ' . $limit_matches[1] . ' ', $query);
    $query = str_ireplace('SELECT ', 'SELECT TOP ' . $limit_matches[1] . ' ', $query);

    New:

    $command_pos = stripos($query, 'DELETE ');
    if (command_pos === false) $command_pos = stripos($query, 'SELECT ');
    if (command_pos !== false) $query = substr_replace($query, 'TOP ' . $limit_matches[1] . ' ', $command_pos + 7, 0);

    http://wordpress.org/extend/plugins/wordpress-database-abstraction/

  2. markegli
    Member
    Posted 1 year ago #

    Marking as resolved.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.