• Resolved thierryyyyyyy

    (@thierryyyyyyy)


    I just update my blog to WP 2.3.

    In a single post page (use single.php of theme), I have a database error :

    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘AS p WHERE p.post_date < ‘2007-09-08 14:27:23’ AND p.post_type = ‘post’ AND p. ‘ at line 1]
    SELECT p.ID, p.post_title FROM (wp_posts LEFT JOIN wp_postmeta as pl_wp_postmeta ON (wp_posts.ID = pl_wp_postmeta.post_id)) AS p WHERE p.post_date < ‘2007-09-08 14:27:23’ AND p.post_type = ‘post’ AND p. (wp_posts.post_status = ‘publish’ OR (wp_posts.post_status = ‘private’ AND (pl_wp_postmeta.meta_key = ‘post_level’ AND pl_wp_postmeta.meta_value <= 10 ))) ORDER BY p.post_date DESC LIMIT 1

    It comes from the “previous_post_link” and the “next_post_link” function. I have seen in Google that at least 3 blogs have this bug.
    What should I do ? did I updated bad ?

    Actually, the SQL is clearly bad, the position of “AS p” should be just after the “FROM wp_post” and not just before “WHERE”. It means that the function “previous_post_link” construct badly the SQL query, but I don’t want to change a WP function !

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter thierryyyyyyy

    (@thierryyyyyyy)

    I searched more deeply in the code. The “previous_post_link” calls for “get_previous_post” which do the SQL query like that :
    return @$wpdb->get_row("SELECT p.ID, p.post_title FROM $wpdb->posts AS p $join $where $sort");

    It means that “$wpdb->posts” is replace by “(wp_posts LEFT JOIN wp_postmeta as pl_wp_postmeta ON (wp_posts.ID = pl_wp_postmeta.post_id))”.
    It does not make sense to me :

    Thread Starter thierryyyyyyy

    (@thierryyyyyyy)

    I succeed in finding the source of the problem.
    The plugin “Lost Level” (version 1.1.1) is not compatible anymore with wp 2.3 due to a not very clean call to the hook “query”.
    He replaces the “$wpdb->posts” by “(wp_posts LEFT JOIN wp_postmeta as pl_wp_postmeta ON (wp_posts.ID = pl_wp_postmeta.post_id))” which is a non sens when the initial query use a “AS p” syntax.

    I corrected the problem, and I will release the correction on my blog : https://www.2diabolos.com/blog

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘SQL error “AS p” when themes search for previous and next post’ is closed to new replies.