Function and usage of get_linkobjects() in wordpress


Answers ( 1 )


    The get_linkobjects() function in WordPress is used to retrieve an array of link objects associated with a specific category. This function is particularly useful for managing and displaying links on a WordPress site. Here's a detailed explanation of its usage:

    Function Signature:

    get_linkobjects( int $category, string $orderby = 'name', int $limit ): array

    Function Description:

    • Purpose: To get an array of link objects that are associated with a given category.
    • Return Value: It returns an array of link objects.

    Usage Example:

    $links = get_linkobjects(1);
    if ($links) {
        foreach ($links as $link) {
            echo '<li>'.$link->link_name.'<br />'.$link->link_description.'</li>';

    In this example, the function get_linkobjects() is called with the category 1. It retrieves all link objects associated with this category. Each link object's name and description are then displayed in a list format.

    Fields in Link Objects:

    • link_id: Identifier of the link.
    • link_url: URL of the link.
    • link_name: Name of the link.
    • link_image: Image associated with the link.
    • link_target: The target attribute for the link.
    • link_category: Category of the link.
    • link_description: Description of the link.
    • link_visible: Visibility status of the link.
    • link_owner: Owner of the link.
    • link_rating: Rating of the link.
    • link_updated: Last updated timestamp of the link.
    • link_rel: Relationship attribute of the link.
    • link_notes: Additional notes about the link.


    1. $category (int, optional): Specifies the category of links to retrieve. If no category is supplied, links from all categories are returned. Default value is 0.
    2. $orderby (string, optional): Determines the order in which the links are returned. Can be 'id', 'name', 'url', 'description', 'rating', or 'owner'. Prefixing with an underscore reverses the order. Specifying 'rand' returns links in random order. Default is 'name'.
    3. $limit (int, optional): Limits the number of entries returned. If not specified, all entries are shown. Default is 0.

    Related Function:

    • get_bookmarks(): A related function that also retrieves link objects but with more options and flexibility.

    This function is useful for developers who want to display links on their WordPress site in a specific order, filtered by categories, or limited to a certain number. It provides an efficient way to handle link management in WordPress themes and plugins.

Leave an answer