Support » How-To and Troubleshooting » Need to output links and links categories to xml file

Need to output links and links categories to xml file

  • Hi!
    For a website I’m doing, I need to get the links in my wordpress blog, as well as the descriptions of these links, and their different categories. I’m interested in 4 categories, and what would be ideal would be an xml file.
    I made a php script to retrieve data from a database and transform it in an xml file, but when I went to my wordpress db, I realised (with a bit of horror, I must say, as I didn’t expect that at all) that the links were there, as well as their descriptions, but I don’t have any category info in wp_links. I guess it must be linked somewhere with the id of the link, but I really wouldn’t know where to start doing a php that would take the links output, and then get the category from the other wp table. I’m sure it’s doable, it’s just that I don’t have a clue where to start.
    Is there any simple way to get these links as well as their categories ?
    Thanks a lot !

Viewing 2 replies - 1 through 2 (of 2 total)
  • Oh, and BTW, I tried with http://blog.lesenfantsdelo.com/?cat=25&feed=rss2
    25 being the category id of the link category I want, but I don’t get anything back. Is there a category for all the links, and then a subcategory ?

    So, actually, I found the solution. I was totaly into php/mySQL a few years ago, and I designed a website with lots of cross calls from a table to another, I totaly forgot about that.
    Anyway, here is the code, in case someone wants to do the same thing :

    // connection info goes here
    $connection = mysql_connect("$hostname" , "$user" , "$pass");
    $db = mysql_select_db($dbase , $connection);
    $query='SELECT * FROM wp_links AS liens, wp_term_relationships AS relation WHERE liens.link_id=relation.object_id AND relation.term_taxonomy_id=31';
    $result = mysql_query($query, $connection) or die("Impossible d'interroger la base de données");
    $num = mysql_num_rows($result);
    while($line = mysql_fetch_assoc($result)) {
        echo "    <p>".$line["link_name"]."</p>\n";

    Here, I wanted the category of links numbered 31 (you get the term_id in the wp_terms table, where you can find the name of the category you want, then you go to wp_term_taxonomy table and you look for your term_id. You take the corresponding term_taxonomy_id, which you can use in wp_term_relationships to get the list of links from the category you specified)

    There is probably an easier solution, so I’m not marking this topic as resolved yet. I’ll use my solution, but if there’s something better, I’d like to know it đŸ™‚

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Need to output links and links categories to xml file’ is closed to new replies.
Skip to toolbar