I have a number of sports sites with hundreds of thousands of existing news posts. The site also has a custom post type for team and a custom post type for person. I wish to be able to somehow automatically find team names and player names in news post body and hyperlink them to the correct team / player post.

The post names exist with exact player and team names. For example

Lionel Messi << Player post Manchester United << Team post Lionel Messi snubs Manchester United and joins Wolverhampton Wanderers << news post

What approach should I take here?

Bonus karma for this additional consideration. In Drupal the post text filtering actions can be cached against the text filter so that the calculations on the body wouldn't have to be done on every page load. Are there similar considerations in Wordpress to make this relatively efficient?.

1 Answer 1


If I am guessing it right, it would be a 2 step process.

  1. Store the post title and post id in an assosiative array while publishing the posts (save_post_POST_TYPE hook). For ex: array('Post Title' => 101) where 101 being the id of the post. I'd use WordPress Options table to store them and quickly retrieve when needed.

  2. Now, you can hyperlink (str_replace) them on the fly using the_content filter or even better save them as hyperlinked when saving the posts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.