Forums

posts_nav_link broken (3 posts)

  1. llbbl
    Member
    Posted 3 years ago #

    After upgrading from 1.5 to 2.0.1 I discovered that the only thing not working was the posts_nav_link() function in the wp-includes/template-functions-link.php file.

    It gives me this 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 '' at line 1]
    SELECT COUNT(DISTINCT ID) FROM

    It can not find the right database name apparently. I tried uploading the old template-functions-link.php file and that didn't work. I think something got screwed up when wordpress did it's database upgrade.

    Anyone know what's going on?

    I will let know what I figure out. I am sure I will have a solution in the next day or so.

  2. llbbl
    Member
    Posted 3 years ago #

    Ok here is the complete code for the function. I fixed the problem. :D


    function posts_nav_link($sep=' — ', $prelabel='« Previous Page', $nxtlabel='Next Page »') {
    global $request, $posts_per_page, $wpdb, $max_num_pages;

    if ( !is_single() ) {

    if ( 'posts' == get_query_var('what_to_show') ) {
    if ( !isset($max_num_pages) ) {
    preg_match('#FROM (.*) GROUP BY#', $request, $matches);
    $fromwhere = $matches[1];

    if (empty($fromwhere))
    $fromwhere = $wpdb->posts;

    $numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
    $max_num_pages = ceil($numposts / $posts_per_page);
    }
    } else {
    $max_num_pages = 999999;
    }

    if ( $max_num_pages > 1 ) {
    previous_posts_link($prelabel);
    echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep);
    next_posts_link($nxtlabel, $max_page);
    }
    }
    }

    Here is the snippet of code that fixed the problem that I was having.


    if (empty($fromwhere))
    $fromwhere = $wpdb->posts;

    Bascially it was searching the variable $results for the database name and not finding it so my code says if that variable ($fromwhere) is empty then set it equal to the database where I store all my posts. (ssssh don't tell anyone :P)

  3. llbbl
    Member
    Posted 3 years ago #

    I didn't follow the upgrading instructions exactly. :D . The part that I forgot to do was deactivate all the plugins. I also didn't delete the old wordpress files. I just overwrote them with the new ones. Oh well. It is working now. I doubt that this problem I was having had anything to do with the plugins issue, but it might have have have something to do with the old files.

Topic Closed

This topic has been closed to new replies.

About this Topic