views:

201

answers:

2

I have a function that is hooked to WordPress' scheduled cron jobs, that goes through some RSS feeds and adds links.

I can't seem to find a function that will add the links for me, so I have to write them myself using $wpdb. The only problem then is that wp_list_bookmarks() won't recognize them because I don't have a relationship between the link and the link category (which I've understand that has something to do with the wp_term_relationships and wp_term_taxonomy tables to do.

Here's what the query code do so far (which apparently not work):

$wpdb->query("INSERT INTO ".$wpdb->prefix."links (link_url, link_name, link_updated) VALUES ('".mysql_real_escape_string($item->get_permalink())."', '".mysql_real_escape_string($item->get_title())."', '".date('Y-m-d H:i:s')."')");
$last_insert_id = $wpdb->insert_id;
$wpdb->query("INSERT INTO ".$wpdb->prefix."term_relationships VALUES ('".$last_insert_id."', '".$category_id."', '0'");
$wpdb->query("UPDATE ".$wpdb->prefix."term_taxonomy SET count = count+1 WHERE term_id = '".$category_id."'");

But I can't figure out how to make this work, anyone else knows how to programatically add links?

+1  A: 

This is an interesting question. I didn't find an "add_bookmarks" for example in Wordpress function reference.

To accomplish your goal, I would read get_bookmarks source code to understand exactly how are the tables implemented and write a function (add_bookmark for example) in functions.php.

I do believe that if you create this function you should get in touch with Wordpress developers since it's something interesting to add to Wordpress core in next versions.

GmonC
If I get this to work, I'll let them know. Thanks! :)
rebellion
+1  A: 

wp_insert_link() is what you want. It's in wp-admin/includes/bookmark.php

We've bounced around on what to name links. Blogroll, Bookmarks, Links, etc — ergo the naming mismatch.

Mark Jaquith
Fantastic! But where do I define the link category? As far as I see, the function checks if `$linkcategory` is set, but the function won't take the link category, or can I just provide the link category in the link data array?
rebellion
`Fatal error: Call to undefined function wp_insert_link()`. I'm using WP 2.9b1.
rebellion