trackback

Send a Trackback.

Description

(int|false|void) trackback( (string) $trackback_url, (string) $title, (string) $excerpt, (int) $ID ); 

Updates database when sending trackback to prevent duplicates.

Returns (int|false|void)

Database query from update.

Parameters (4)

0. $trackback_url (string)
URL to send trackbacks.
1. $title (string)
Title of post.
2. $excerpt (string)
Excerpt of post.
3. $id (int)
Post ID.

Usage

  1. if ( !function_exists( 'trackback' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4. // URL to send trackbacks. 
  5. $trackback_url = ''; 
  6.  
  7. // Title of post. 
  8. $title = ''; 
  9.  
  10. // Excerpt of post. 
  11. $excerpt = ''; 
  12.  
  13. // Post ID. 
  14. $id = -1; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = trackback($trackback_url, $title, $excerpt, $id); 
  18.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment.php  
  1. function trackback($trackback_url, $title, $excerpt, $ID) { 
  2. global $wpdb; 
  3.  
  4. if ( empty($trackback_url) ) 
  5. return; 
  6.  
  7. $options = array(); 
  8. $options['timeout'] = 10; 
  9. $options['body'] = array( 
  10. 'title' => $title,  
  11. 'url' => get_permalink($ID),  
  12. 'blog_name' => get_option('blogname'),  
  13. 'excerpt' => $excerpt 
  14. ); 
  15.  
  16. $response = wp_safe_remote_post( $trackback_url, $options ); 
  17.  
  18. if ( is_wp_error( $response ) ) 
  19. return; 
  20.  
  21. $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $ID) ); 
  22. return $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $ID) );