Using WordPress ‘get_bookmarks()’ PHP function

The get_bookmarks() WordPress PHP function retrieves the list of bookmarks.

Usage

$bookmarks = get_bookmarks($args);

Parameters

  • $args (string|array) Optional – String or array of arguments to retrieve bookmarks.

    • orderby (string) – How to order the links by. Accepts ‘id’, ‘link_id’, ‘name’, ‘link_name’, ‘url’, ‘link_url’, ‘visible’, ‘link_visible’, ‘rating’, ‘link_rating’, ‘owner’, ‘link_owner’, ‘updated’, ‘link_updated’, ‘notes’, ‘link_notes’, ‘description’, ‘link_description’, ‘length’, and ‘rand’. When $orderby is ‘length’, orders by the character length of ‘link_name’. Default ‘name’.

    • order (string) – Whether to order bookmarks in ascending or descending order. Accepts ‘ASC’ (ascending) or ‘DESC’ (descending). Default ‘ASC’.

    • limit (int) – Amount of bookmarks to display. Accepts any positive number or -1 for all. Default -1.

    • category (string) – Comma-separated list of category IDs to include links from.

    • category_name (string) – Category to retrieve links for by name.

    • hide_invisible (int|bool) – Whether to show or hide links marked as ‘invisible’. Accepts 1|true or 0|false. Default 1|true.

    • show_updated (int|bool) – Whether to display the time the bookmark was last updated. Accepts 1|true or 0|false. Default 0|false.

    • include (string) – Comma-separated list of bookmark IDs to include.

    • exclude (string) – Comma-separated list of bookmark IDs to exclude.

    • search (string) – Search terms. Will be SQL-formatted with wildcards before and after and searched in ‘link_url’, ‘link_name’, and ‘link_description’. Default: ”.

More information

See WordPress Developer Resources: get_bookmarks()

Examples

$bookmarks = get_bookmarks(array(
  'orderby' => 'name',
  'order' => 'ASC',
  'category_name' => 'Related Sites'
));

foreach ($bookmarks as $bookmark) {
  printf('<a class="relatedlink" href="%1$s">%2$s</a><br />', esc_attr($bookmark->link_url), $bookmark->link_name);
}

Retrieve bookmarks with a limit of 5

$bookmarks = get_bookmarks(array(
  'orderby' => 'name',
  'order' => 'ASC',
  'limit' => 5
));

foreach ($bookmarks as $bookmark) {
  printf('<a href="%1$s">%2$s</a><br />', esc_attr($bookmark->link_url), $bookmark->link_name);
}