WordPress.org

Ready to get started?Download WordPress

Forums

Unable to access tables with different prefix (1 post)

  1. bmeisler
    Member
    Posted 3 years ago #

    For a number of reasons, I've split my site into two wp installs, www and blog. I'd like to be able to access recent posts from www and print them on blog, and I thought I could do this by having both wp installations share the same database. I tried to access www posts from within blog by using set_prefix, like so:

    global $wpdb
    $wpdb->set_prefix('www');
    $querystr ="
    SELECT $wpdb->posts.* FROM $wpdb->posts
    WHERE $wpdb->posts.post_type = 'post'
    ORDER BY $wpdb->posts.post_date DESC
    LIMIT 5";
    $pageposts = $wpdb->get_results($querystr, OBJECT);

    But $pageposts is empty.

    Any idea what I'm doing wrong?

Topic Closed

This topic has been closed to new replies.

About this Topic