WordPress.org

Ready to get started?Download WordPress

Forums

Need help displaying second wordpress content (7 posts)

  1. jamesbe
    Member
    Posted 5 years ago #

    Hi, I have been searching and hacking away at code but I cannot get this to work.

    I have 2 wordpress installations (both the same version).

    On installation one's front page I would like to put the "latest 10" posts from installation two's database.

    I can create a php script and it works on it's own but when I include it into the front page of my installation one, it uses the wrong database.

    Is there a way to "switch" which database I am connected to on the fly and switch back? Actually it is even the same database just different prefixes for the 2 installations.

    Any help would be greatly appreciated -- there are a few things I need to with this.

    1) Get the latest 10 posts title and permalink only
    2) Get the latest post excerpt and permalink and title.

  2. whooami
    Member
    Posted 5 years ago #

    if youre making a second mysql connection, you need to use the new_link parameter with mysql_connect:

    http://us3.php.net/function.mysql-connect

  3. jamesbe
    Member
    Posted 5 years ago #

    Hi! Thank you for your quick response!

    Perhaps this is what will help me on my way but I guess I am lost on how to make the new connection within wordpress.

    Or will I have to basically create a new connection with PHP and forget using any of wordpress's functions, and build my own query manually?

  4. whooami
    Member
    Posted 5 years ago #

    I am lost ...

    I can create a php script and it works on it's own but when I include it into the front page of my installation one, it uses the wrong database.

    whats in the script you are using? if youre trying to use wordpress' built in functions, youre going to need to make more changes .. as, off the shelf, wordpress' db api thingy is only set up to look in one database at a time, at tables that all contain a common prefix.

  5. jamesbe
    Member
    Posted 5 years ago #

    This is what I did... which works when you point to the page by itself but not as an include:

    [code]
    <?php
    define('WP_USE_THEMES', false);
    require("/var/www/html/luxurycars/wp-blog-header.php");
    ?>

    <?php
    query_posts('&showposts=3');

    if (have_posts()) :
    while (have_posts()) : the_post();
    ?>
    href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php
    $title = str_replace('Test Drive:','',the_title('','',false));
    $title = str_replace('First Drive:','',$title);
    ?>"><?php the_title(); ?>

    <? endwhile;
    endif; rewind_posts(); ?>
    [/code]

  6. whooami
    Member
    Posted 5 years ago #

    like I said ...

    if youre trying to use wordpress' built in functions, ...

  7. jamesbe
    Member
    Posted 5 years ago #

    So I'll have to create a dbconnection somehow manually and query manually then?

    How do I get the permalink then? I don't see those in the Database at all...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.