SQL - get title and url from WP database

Discussion in 'PHP' started by emalker, Oct 24, 2010.

  1. #1
    Hi

    I would like a list of all titles and urls from a WordPress database - is there someone who can create an SQL command for this?
     
    emalker, Oct 24, 2010 IP
  2. KingOle

    KingOle Peon

    Messages:
    69
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Based on the WP DB schema:

    
    SELECT post_title FROM wp_posts;
    SELECT link_url, link_name FROM wp_links;
    
    Code (markup):
    If you don't want the name of the link, just remove it from above. I can't see a way in which wp_posts are linked to the wp_links table so I help this helps.
     
    KingOle, Oct 24, 2010 IP
  3. dddougal

    dddougal Well-Known Member

    Messages:
    676
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    108
    #3
    You dont need to access the database directly, use wordpress's built in functions, its much easier.
     
    dddougal, Oct 24, 2010 IP
  4. emalker

    emalker Active Member

    Messages:
    91
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #4
    thanks - but is it possible to pull it out together?
     
    emalker, Oct 24, 2010 IP
  5. emalker

    emalker Active Member

    Messages:
    91
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #5
    @dddougal exports breaks when I export (I have 10,000 + posts)
     
    emalker, Oct 24, 2010 IP
  6. KingOle

    KingOle Peon

    Messages:
    69
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Have you tried downloading a copy of your database (maybe via SSH) and then doing the queries then? Or perhaps changing some server settings to allow for longer queries?
     
    KingOle, Oct 25, 2010 IP
  7. emalker

    emalker Active Member

    Messages:
    91
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #7
    This work

    <?
    require_once("wp-config.php");
    
    $dbname = constant("DB_NAME");
    
    $dbuser = constant("DB_USER");
    
    $dbpassword = constant("DB_PASSWORD");
    
    $dbhost = constant("DB_HOST");
    
    $tablename = "$table_prefix"."posts";
    $connect = mysql_connect("$dbhost","$dbuser","$dbpassword");
    mysql_select_db("$dbname");
    
    $spostsprint = mysql_query("SELECT ID,post_title,guid FROM $tablename ORDER BY ID");
    WHILE($postsprint = mysql_fetch_array($spostsprint)) {
    $titleprint = utf8_decode($postsprint[post_title]);
    print"$titleprint,$postsprint[guid]<br />";
    }
    ?>
    PHP:
     
    emalker, Oct 27, 2010 IP