The get_linkrating() WordPress PHP function is a legacy function used to retrieve the value of a link’s link_rating
field.
Usage
get_linkrating($link);
Input:
$link = (object) array('link_rating' => 5);
Output:
5
Parameters
$link
(object) – Required. The link object for which thelink_rating
value needs to be retrieved.
More information
See WordPress Developer Resources: get_linkrating()
This function is deprecated as of WordPress 2.1.0. Use sanitize_bookmark_field()
instead.
Examples
Display the link rating for a specific link
$link = (object) array('link_rating' => 4); $rating = get_linkrating($link); echo "The link rating is: " . $rating;
Add the link rating to an array of link objects
$links = array( (object) array('name' => 'Link 1', 'link_rating' => 3), (object) array('name' => 'Link 2', 'link_rating' => 5) ); foreach ($links as $link) { $link->rating = get_linkrating($link); }
Filter links by a minimum rating
$links = array( (object) array('name' => 'Link 1', 'link_rating' => 2), (object) array('name' => 'Link 2', 'link_rating' => 4) ); $min_rating = 3; $filtered_links = array_filter($links, function($link) use ($min_rating) { return get_linkrating($link) >= $min_rating; });
Sort links by rating
$links = array( (object) array('name' => 'Link 1', 'link_rating' => 3), (object) array('name' => 'Link 2', 'link_rating' => 1) ); usort($links, function($link1, $link2) { return get_linkrating($link2) <=> get_linkrating($link1); });
Calculate the average rating of a set of links
$links = array( (object) array('name' => 'Link 1', 'link_rating' => 2), (object) array('name' => 'Link 2', 'link_rating' => 4) ); $total_rating = 0; foreach ($links as $link) { $total_rating += get_linkrating($link); } $average_rating = $total_rating / count($links);