• jmkprime

    (@jmkprime)


    I use to use an old hack that I’d picked up around here for assigning a special category to link posts so that the except was used for the url and the post was displayed as a single link — something along the lines of the_title (unfortunately I forget who posted it up).

    I’ve recently moved over to using del.icio.us for keeping track of timely links and wanted to copy my link posts over to it. I was surprised how easy it was so I thought I’d post up the code to see if it is useful to anybody else.

    This uses the del.icio.us API. $delusername and $delpassword are set to your del.icio.us username and password. $cat_id is whatever category number identifies the link posts. After you’ve made the normal database connection, you’d run:


    $delbaseuri = "del.icio.us/api";
    $query = "SELECT distinct(wp_post2cat.post_id), wp_posts.post_title as title, wp_posts.post_date as created_at, wp_posts.post_excerpt as url FROM wp_posts, wp_post2cat WHERE wp_post2cat.category_id=".$cat_id." AND wp_posts.ID=wp_post2cat.post_id";

    foreach ( array_query($query) as $post ) {
    $dt = explode(' ',$post['created_at']);
    $url = "http://".$delusername.":".$delpassword."@".$delbaseuri."/posts/add?url=". urlencode($post['url']). "&description=". urlencode($post['title'])."&dt=".urlencode($dt[0].'T'.$dt[1].'Z')."&replace=yes";
    $result = file_get_contents($url);
    sleep(1);
    }

    The sleep term is from the API documentation — they request a 1 sec delay between each automated hit. One downside is that it doesn’t automatically add tags, but it shouldn’t be too hard to add it you already have them in the wp database.

The topic ‘Export link posts to del.icio.us’ is closed to new replies.