Results 1 to 5 of 5

Thread: Connect to Wordpress Database?

Hybrid View

  1. #1
    Join Date
    Jul 2009
    NC, USA

    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

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

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

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


    // 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))
    $row['post_status'] == "publish") {
    "".$row['post_title']." <br />";
    that would output something similar to:

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

  3. #3
    Join Date
    Jul 2009
    NC, USA
    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


    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
    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, 04:35 AM
  4. [WTS] WordPress Database: Family Life Articles
    By kapengbarako in forum Content
    Replies: 1
    Last Post: 20 November, 2009, 16: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


Posting Permissions

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