Using WordPress ‘get_pung()’ PHP function

The get_pung() WordPress PHP function retrieves a list of URLs that have already been pinged for a specific post.

Usage

To use the function, simply pass the post ID or object as a parameter:

get_pung($post);

Parameters

  • $post (int|WP_Post): Required. The post ID or object for which you want to retrieve the pinged URLs.

More information

See WordPress Developer Resources: get_pung()
This function was introduced in WordPress version 1.5.0.

Examples

Display pinged URLs for a post

This code snippet displays the list of pinged URLs for a given post.

$pinged_posts = get_pung($post->ID);
foreach ($pinged_posts as $pinged_post) {
  if (!empty($pinged_post)) {
    echo 'Incoming Link: <a href="' . $pinged_post . '" rel="external">' . $pinged_post . '</a>';
  }
}

Count pinged URLs for a post

This code snippet counts the number of pinged URLs for a given post.

$pinged_posts = get_pung($post->ID);
$pinged_count = count($pinged_posts);
echo 'Pinged URLs count: ' . $pinged_count;

Display pinged URLs with a custom message

This code snippet displays pinged URLs for a given post with a custom message.

$pinged_posts = get_pung($post->ID);
foreach ($pinged_posts as $pinged_post) {
  if (!empty($pinged_post)) {
    echo 'Referenced by: <a href="' . $pinged_post . '" rel="external">' . $pinged_post . '</a>';
  }
}

List pinged URLs in an unordered list

This code snippet displays pinged URLs for a given post as an unordered list.

$pinged_posts = get_pung($post->ID);
echo '<ul>';
foreach ($pinged_posts as $pinged_post) {
  if (!empty($pinged_post)) {
    echo '<li><a href="' . $pinged_post . '" rel="external">' . $pinged_post . '</a></li>';
  }
}
echo '</ul>';

Display pinged URLs with the date they were added

This code snippet displays the pinged URLs for a given post along with the date they were added.

$pinged_posts = get_pung($post->ID);
foreach ($pinged_posts as $pinged_post) {
  if (!empty($pinged_post)) {
    $ping_date = date('F j, Y', strtotime($pinged_post));
    echo 'Incoming Link on ' . $ping_date . ': <a href="' . $pinged_post . '" rel="external">' . $pinged_post . '</a>';
  }
}

Tagged in

Leave a Comment

Your email address will not be published. Required fields are marked *