Using WordPress ‘get_linkobjectsbyname()’ PHP function

The get_linkobjectsbyname() WordPress PHP function retrieves an array of link objects associated with a specific category name.

Usage

$links = get_linkobjectsbyname('fred');
foreach ($links as $link) {
    echo '<a href="' . $link->link_url . '">' . $link->link_name . '</a><br>';
}

Parameters

  • $cat_name (string, optional): The category name to use. If no match is found, uses all. Default ‘noname’.
  • $orderby (string, optional): The order to output the links. E.g. ‘id’, ‘name’, ‘url’, ‘description’, ‘rating’, or ‘owner’. Default ‘name’. If you start the name with an underscore, the order will be reversed. Specifying ‘rand’ as the order will return links in a random order.
  • $limit (int, optional): Limit to X entries. If not specified, all entries are shown. Default: -1

More information

See WordPress Developer Resources: get_linkobjectsbyname

Examples

Retrieve and display links associated with a specific category, ‘Friends’:

$friends_links = get_linkobjectsbyname('Friends');
foreach ($friends_links as $link) {
    echo '<a href="' . $link->link_url . '">' . $link->link_name . '</a><br>';
}

Retrieve and display links ordered by their URLs:

$links = get_linkobjectsbyname('noname', 'url');
foreach ($links as $link) {
    echo '<a href="' . $link->link_url . '">' . $link->link_name . '</a><br>';
}

Retrieve and display links in reverse alphabetical order:

$links = get_linkobjectsbyname('noname', '_name');
foreach ($links as $link) {
    echo '<a href="' . $link->link_url . '">' . $link->link_name . '</a><br>';
}

Retrieve and display only 5 links:

$links = get_linkobjectsbyname('noname', 'name', 5);
foreach ($links as $link) {
    echo '<a href="' . $link->link_url . '">' . $link->link_name . '</a><br>';
}

Retrieve and display links in a random order:

$links = get_linkobjectsbyname('noname', 'rand');
foreach ($links as $link) {
    echo '<a href="' . $link->link_url . '">' . $link->link_name . '</a><br>';
}