post-levels update for WordPress 2.3

I made an update for the post-levels plugin so it works with WordPress 2.3

The plugin was throwing sql errors.

WordPress database error: [Column ‘post_id’ in field list is ambiguous]
SELECT post_id, meta_value FROM wp_postmeta, (wp_posts LEFT JOIN wp_postmeta as pl_wp_postmeta ON (wp_posts.ID = pl_wp_postmeta.post_id)) WHERE post_id = ID AND meta_key = ‘links_to’ AND (post_status = ‘static’ OR (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 <= 1 ))))

WordPress database error: [Column ‘post_id’ in field list is ambiguous]
SELECT post_id, meta_value FROM wp_postmeta, (wp_posts LEFT JOIN wp_postmeta as pl_wp_postmeta ON (wp_posts.ID = pl_wp_postmeta.post_id)) WHERE post_id = ID AND meta_key = ‘links_to_target’ AND (post_status = ‘static’ OR (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 <= 1 ))))

Here’s the fix:

 

function postlevels_query_cleanup($sql)
{
    global $wpdb;

// fix for WordPress 2.3
// evilzenscientist – 2 Oct 07

    $sql = preg_replace(“/post_id/”, “wp_postmeta.post_id”, $sql);
    $sql = preg_replace(“/, meta_value/”, “, wp_postmeta.meta_value”, $sql);
    $sql = preg_replace(“/meta_key/”, “wp_postmeta.meta_key”, $sql);

// end

 

Here’s the new plugin. It’s not really tested – except it works for me.

24 Replies to “post-levels update for WordPress 2.3”

  1. I’ve been waiting for PostLevel to update, but it seems to be on a slow process? I’ve tried to get it to work with 2.3, but I don’t have to play around with the file. Thank you! It works great =)

  2. I’ve been waiting for PostLevel to update, but it seems to be on a slow process? I’ve tried to get it to work with 2.3, but I don’t have to play around with the file. Thank you! It works great =)

  3. I put this in, just as described, and it blew up.

    I get the following error:

    Parse error: syntax error, unexpected ‘,’ in /mnt/Target01/3275342/www.mydomain.com/web/content/wp-content/plugins/post-levels.php on line 253

    Any thoughts? I’m running WP 2.3

  4. I put this in, just as described, and it blew up.

    I get the following error:

    Parse error: syntax error, unexpected ‘,’ in /mnt/Target01/3275342/www.mydomain.com/web/content/wp-content/plugins/post-levels.php on line 253

    Any thoughts? I’m running WP 2.3

  5. As Parker said, the syntax error is in this line:

    $sql = preg_replace(”/, meta_value/”, “, wp_postmeta.meta_value”, $sql);

    I’ve tried pulling out each “,” but either get uglier errors, or the same.

    I comment out the line all together and I get fun stuff like:

    Warning: preg_replace() [function.preg-replace]: Empty regular expression in /home/website/ line 249

    Warning: Division by zero in /home/website/ line 249

  6. As Parker said, the syntax error is in this line:

    $sql = preg_replace(”/, meta_value/”, “, wp_postmeta.meta_value”, $sql);

    I’ve tried pulling out each “,” but either get uglier errors, or the same.

    I comment out the line all together and I get fun stuff like:

    Warning: preg_replace() [function.preg-replace]: Empty regular expression in /home/website/ line 249

    Warning: Division by zero in /home/website/ line 249

  7. Hey,
    you don’t have to pull out EACH one of “, but only here:

    $sql = preg_replace(”/post_id/”,
    $sql = preg_replace(”/, meta_value/”,
    $sql = preg_replace(”/meta_key/”,

    Let the other ones as they are!

  8. Hey,
    you don’t have to pull out EACH one of “, but only here:

    $sql = preg_replace(”/post_id/”,
    $sql = preg_replace(”/, meta_value/”,
    $sql = preg_replace(”/meta_key/”,

    Let the other ones as they are!

  9. Hey,
    you don’t have to pull out EACH one of “, but only here:

    $sql = preg_replace(”/post_id/”,
    $sql = preg_replace(”/, meta_value/”,
    $sql = preg_replace(”/meta_key/”,

    Let the other ones as they are!

  10. Oh by the way, the exact error for me is
    Erreur de la base de données de WordPress : [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 ‘p WHERE p.post_date < ‘2007-11-04 16:33:57’ AND p.post_type = ‘post’ AND p. (wp’ at line 1]
    SELECT p.ID, p.post_title FROM (wpfr_posts LEFT JOIN wpfr_postmeta as pl_wpfr_postmeta ON (wpfr_posts.ID = pl_wpfr_postmeta.post_id)) AS p WHERE p.post_date < ‘2007-11-04 16:33:57’ AND p.post_type = ‘post’ AND p. (wpfr_posts.post_status = ‘publish’ OR (wpfr_posts.post_status = ‘private’ AND (pl_wpfr_postmeta.meta_key = ‘post_level’ AND pl_wpfr_postmeta.meta_value <= 5 ))) ORDER BY p.post_date DESC LIMIT 1

  11. Oh by the way, the exact error for me is
    Erreur de la base de données de WordPress : [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 ‘p WHERE p.post_date < ‘2007-11-04 16:33:57’ AND p.post_type = ‘post’ AND p. (wp’ at line 1]
    SELECT p.ID, p.post_title FROM (wpfr_posts LEFT JOIN wpfr_postmeta as pl_wpfr_postmeta ON (wpfr_posts.ID = pl_wpfr_postmeta.post_id)) AS p WHERE p.post_date < ‘2007-11-04 16:33:57’ AND p.post_type = ‘post’ AND p. (wpfr_posts.post_status = ‘publish’ OR (wpfr_posts.post_status = ‘private’ AND (pl_wpfr_postmeta.meta_key = ‘post_level’ AND pl_wpfr_postmeta.meta_value <= 5 ))) ORDER BY p.post_date DESC LIMIT 1

  12. yeah, i get similar errors:

    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 ‘p WHERE p.post_date < ‘2007-11-18 20:14:12’ AND p.post_type = ‘post’ AND p. (wp’ at line 1]
    SELECT p.ID, p.post_title FROM (wp_posts LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id) AS p WHERE p.post_date < ‘2007-11-18 20:14:12’ AND p.post_type = ‘post’ AND p. (wp_posts.post_status = ‘publish’ OR (wp_posts.post_status = ‘private’ AND (wp_postmeta.meta_key = ‘post_level’ AND wp_postmeta.meta_value ‘2007-11-18 20:14:12’ AND p.post_type = ‘post’ AND p. (wp’ at line 1]
    SELECT p.ID, p.post_title FROM (wp_posts LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id) AS p WHERE p.post_date > ‘2007-11-18 20:14:12’ AND p.post_type = ‘post’ AND p. (wp_posts.post_status = ‘publish’ OR (wp_posts.post_status = ‘private’ AND (wp_postmeta.meta_key = ‘post_level’ AND wp_postmeta.meta_value <= 9 ))) AND p.ID != 586 ORDER BY p.post_date ASC LIMIT 1

  13. yeah, i get similar errors:

    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 ‘p WHERE p.post_date < ‘2007-11-18 20:14:12’ AND p.post_type = ‘post’ AND p. (wp’ at line 1]
    SELECT p.ID, p.post_title FROM (wp_posts LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id) AS p WHERE p.post_date < ‘2007-11-18 20:14:12’ AND p.post_type = ‘post’ AND p. (wp_posts.post_status = ‘publish’ OR (wp_posts.post_status = ‘private’ AND (wp_postmeta.meta_key = ‘post_level’ AND wp_postmeta.meta_value ‘2007-11-18 20:14:12’ AND p.post_type = ‘post’ AND p. (wp’ at line 1]
    SELECT p.ID, p.post_title FROM (wp_posts LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id) AS p WHERE p.post_date > ‘2007-11-18 20:14:12’ AND p.post_type = ‘post’ AND p. (wp_posts.post_status = ‘publish’ OR (wp_posts.post_status = ‘private’ AND (wp_postmeta.meta_key = ‘post_level’ AND wp_postmeta.meta_value <= 9 ))) AND p.ID != 586 ORDER BY p.post_date ASC LIMIT 1

  14. I tried to use this plugin but it’s still generating errors. I hope it can be fixed because I don’t want all of my private posts to show up completely.

    The errors are similar as others:

    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-12-15 23:33:51’ AND p.post_type = ‘post’ AND p. ‘ at line 1]
    SELECT p.ID, p.post_title FROM (b2posts JOIN b2postmeta as pl_b2postmeta ON (b2posts.ID = pl_b2postmeta.post_id)) AS p WHERE p.post_date < ‘2007-12-15 23:33:51’ AND p.post_type = ‘post’ AND p. (b2posts.post_status = ‘publish’ OR (b2posts.post_status = ‘private’ AND (pl_b2postmeta.meta_key = ‘post_level’ AND pl_b2postmeta.meta_value ‘2007-12-15 23:33:51’ AND p.post_type = ‘post’ AND p. ‘ at line 1]
    SELECT p.ID, p.post_title FROM (b2posts JOIN b2postmeta as pl_b2postmeta ON (b2posts.ID = pl_b2postmeta.post_id)) AS p WHERE p.post_date > ‘2007-12-15 23:33:51’ AND p.post_type = ‘post’ AND p. (b2posts.post_status = ‘publish’ OR (b2posts.post_status = ‘private’ AND (pl_b2postmeta.meta_key = ‘post_level’ AND pl_b2postmeta.meta_value <= 0 ))) AND p.ID != 845 ORDER BY p.post_date ASC LIMIT 1

  15. I tried to use this plugin but it’s still generating errors. I hope it can be fixed because I don’t want all of my private posts to show up completely.

    The errors are similar as others:

    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-12-15 23:33:51’ AND p.post_type = ‘post’ AND p. ‘ at line 1]
    SELECT p.ID, p.post_title FROM (b2posts JOIN b2postmeta as pl_b2postmeta ON (b2posts.ID = pl_b2postmeta.post_id)) AS p WHERE p.post_date < ‘2007-12-15 23:33:51’ AND p.post_type = ‘post’ AND p. (b2posts.post_status = ‘publish’ OR (b2posts.post_status = ‘private’ AND (pl_b2postmeta.meta_key = ‘post_level’ AND pl_b2postmeta.meta_value ‘2007-12-15 23:33:51’ AND p.post_type = ‘post’ AND p. ‘ at line 1]
    SELECT p.ID, p.post_title FROM (b2posts JOIN b2postmeta as pl_b2postmeta ON (b2posts.ID = pl_b2postmeta.post_id)) AS p WHERE p.post_date > ‘2007-12-15 23:33:51’ AND p.post_type = ‘post’ AND p. (b2posts.post_status = ‘publish’ OR (b2posts.post_status = ‘private’ AND (pl_b2postmeta.meta_key = ‘post_level’ AND pl_b2postmeta.meta_value <= 0 ))) AND p.ID != 845 ORDER BY p.post_date ASC LIMIT 1

  16. I tried to use this plugin but it’s still generating errors. I hope it can be fixed because I don’t want all of my private posts to show up completely.

    The errors are similar as others:

    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-12-15 23:33:51’ AND p.post_type = ‘post’ AND p. ‘ at line 1]
    SELECT p.ID, p.post_title FROM (b2posts JOIN b2postmeta as pl_b2postmeta ON (b2posts.ID = pl_b2postmeta.post_id)) AS p WHERE p.post_date < ‘2007-12-15 23:33:51’ AND p.post_type = ‘post’ AND p. (b2posts.post_status = ‘publish’ OR (b2posts.post_status = ‘private’ AND (pl_b2postmeta.meta_key = ‘post_level’ AND pl_b2postmeta.meta_value ‘2007-12-15 23:33:51’ AND p.post_type = ‘post’ AND p. ‘ at line 1]
    SELECT p.ID, p.post_title FROM (b2posts JOIN b2postmeta as pl_b2postmeta ON (b2posts.ID = pl_b2postmeta.post_id)) AS p WHERE p.post_date > ‘2007-12-15 23:33:51’ AND p.post_type = ‘post’ AND p. (b2posts.post_status = ‘publish’ OR (b2posts.post_status = ‘private’ AND (pl_b2postmeta.meta_key = ‘post_level’ AND pl_b2postmeta.meta_value <= 0 ))) AND p.ID != 845 ORDER BY p.post_date ASC LIMIT 1

Leave a Reply

Your email address will not be published. Required fields are marked *