How to programmatically add WordPress links / bookmarks?

I have a function that is connected to scheduled WordPress cron jobs that views some RSS feeds and adds links.

I can't seem to find a function that will add links for me, so I have to write them myself using $wpdb. The only problem is that it wp_list_bookmarks()does not recognize them, because I have no connection between the link and the category of the link (which, as I understand it, is connected with wp_term_relationshipsand wp_term_taxonomy.

Here's what the request code does (which obviously doesn't 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, does anyone else know how to programmatically add links?

+3
2

wp_insert_link() - , . wp-admin/includes/bookmark.php

, . Blogroll, Bookmarks, Links .. - ergo .

+4

. "add_bookmarks", , Wordpress.

, get_bookmarks , , (add_bookmark ) functions.php.

, , Wordpress, Wordpress .

+1

Source: https://habr.com/ru/post/1725561/


All Articles