<?php

/*
Plugin Name: WP Automatic Reference In Tag
Plugin URI: http://pagememo.blogspot.com/
Version: 1.01b
Author: J.Matsushima(Original version by Jose Sanchez Martin [http://www.automaticjack.tv])
Description: This plugin makes autolinks from the title of your post and your link database, just type the post title "included tags". For example "&lt;strong&gt;post title&lt;/strong&gt;".
*/

function autoenlace($texto)
{

global $wpdb, $tableposts, $post;
$enlaces=array();
$i=0;

$autoposts = 1;

if ($autoposts==1) {
	$request = "SELECT ID, post_title FROM $tableposts WHERE post_status = 'publish' and ID<>".$post->ID." ORDER BY post_title";
	$envios = $wpdb->get_results($request);
	foreach ($envios as $envio) {
		$post_title = stripslashes($envio->post_title);
		$permalink = get_permalink($envio->ID);
		$enlace = '><a href="' . $permalink . '" rel="bookmark" title="' . $post_title . '">' . $post_title . '</a><';//add tag mark
		$post_title = '>'.$post_title.'<';//add tag mark
		$enlaces[$post_title] = $enlace;
	}
}

foreach($enlaces as $buscado => $sustituido) {   
	$texto = ereg_replace($buscado,$sustituido,$texto);
}

return $texto;

}

add_filter('the_content', 'autoenlace', 9); 

?>