It looks like the default get_bookmarks()
http://codex.wordpress.org/Function_Reference/get_bookmarks
is using this query:
SELECT * FROM wp_links WHERE 1=1 AND link_visible="Y" ORDER BY link_name ASC;
You can check the function in /wp-includes/bookmark.php
.
The get_bookmarks()
function has limit
and order
parameters that you might find helpful.
The option get_bookmarks("limit=5")
gives this query:
SELECT * FROM wp_links WHERE 1=1 AND link_visible="Y" ORDER BY link_name ASC LIMIT 5
The category parameter get_bookmarks("category=1")
gives you this one with JOIN
:
SELECT * FROM wp_links
INNER JOIN wp_term_relationships AS tr ON (wp_links.link_id = tr.object_id)
INNER JOIN wp_term_taxonomy as tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
WHERE 1=1 AND link_visible="Y" AND ( tt.term_id = 1 ) AND taxonomy = 'link_category'
ORDER BY link_name ASC;
So if you don’t use the category parameters, these are just plain SELECT
queries that use the $wpdb
Database Object.
Edit: If you want to search for a special link_owner
you can use this example:
global $wpdb;
$link_owner=1; // EDIT this value
$sql="SELECT * FROM wp_links WHERE link_visible="Y" AND link_owner = %d ORDER BY link_name ASC;";
$results = $wpdb->get_results($wpdb->prepare($sql,$link_owner));