Using WordPress ‘get_linkrating()’ PHP function

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 the link_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

$link = (object) array('link_rating' => 4);
$rating = get_linkrating($link);
echo "The link rating is: " . $rating;
$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);
}
$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;
});
$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);
});
$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);