Results 1 to 5 of 5

Thread: Connect to Wordpress Database?

  1. #1
    CoreyFreeman's Avatar
    CoreyFreeman is offline Experienced Net Builder
    Join Date
    Jul 2009
    Location
    NC, USA
    Posts
    692
    Thanks
    40
    Thanked 55 Times in 47 Posts

    Connect to Wordpress Database?

    I want to automatically connect to the database and pull data from the tables. Can somebody tell me how to do that? I know PHP & MYSQL so I just need to get the files in order to get the query to work...

    I'm working from a theme folder if that's important.

  2. #2
    Aziz's Avatar
    Aziz is offline no investment, no glory
    Join Date
    May 2009
    Location
    IL
    Posts
    736
    Thanks
    588
    Thanked 243 Times in 168 Posts
    hmm

    PHP Code:
    <?php
    // edit these values to match your database information
    $server "localhost";
    $user "root";
    $password "";
    $db "wp";

    $con mysql_connect($server,$user,$password); 

    if (!
    $con) {
        die(
    "database connection error");
    } else {

    mysql_select_db($db$con);

    // example query
    $result mysql_query("SELECT * FROM wp_posts
    WHERE post_author='1'"
    );

    // show all posts by author 1 (admin)
    while($row mysql_fetch_array($result))
      {
        if(
    $row['post_status'] == "publish") {
        echo 
    "".$row['post_title']." <br />";
        }
      }
      
    }
    mysql_close($con);
    ?>
    that would output something similar to:

    Quote Originally Posted by "localhost WP - Aziz
    Hello world!
    About Us
    Lorem Wipsum
    Articles
    All Articles
    Archvies
    contact
    Links
    IRC Chat
    Sitemap

  3. #3
    CoreyFreeman's Avatar
    CoreyFreeman is offline Experienced Net Builder
    Join Date
    Jul 2009
    Location
    NC, USA
    Posts
    692
    Thanks
    40
    Thanked 55 Times in 47 Posts
    I'm building a theme to sell, so I need to be able to use any details that someone has without having to edit the login information. Any ideas?

  4. #4
    moonsoup is offline Unknown Net Builder
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Super

    You mean like this?
    Class Reference/wpdb � WordPress Codex

    Lol - a little late!
    Last edited by moonsoup; 29 May, 2012 at 01:14 AM. Reason: clarify reason.

  5. #5
    iowadawg's Avatar
    iowadawg is online now Free Cell Champion
    Join Date
    May 2010
    Location
    Not in Texas
    Posts
    2,011
    Blog Entries
    4
    Thanks
    165
    Thanked 353 Times in 302 Posts
    I would believe that after almost 2 1/2 years, he has solved his problem.
    Can't believe people come into forums and then hunt for some very old thread to answer as their first post!

Similar Threads

  1. Gamers Connect
    By Prime in forum Post Exchange
    Replies: 2
    Last Post: 9 May, 2010, 22:31 PM
  2. How to import database to Wordpress?
    By thesyndicate in forum Wordpress
    Replies: 6
    Last Post: 12 April, 2010, 22:15 PM
  3. [WTS] Wordpress Database of Law/Legal Articles
    By kapengbarako in forum Content
    Replies: 1
    Last Post: 22 February, 2010, 03:35 AM
  4. [WTS] WordPress Database: Family Life Articles
    By kapengbarako in forum Content
    Replies: 1
    Last Post: 20 November, 2009, 15:21 PM
  5. Let's Connect on StumbleUpon!
    By gloson in forum General Chat
    Replies: 1
    Last Post: 9 May, 2009, 17:50 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •