If I want to "safely" delete a post. I want to make sure that no link exists (within my blog) to "to-be-deleted" post. How do I do that?
-
Not sure how to do this but maybe you cant try this: Move the post to trash and use a link checker plugin. If the link checker plugin is clever enough it should tell you any links linking to the post you have no longer visible on the site.– ScottMay 10, 2011 at 9:22
-
1+1 for a great question. Idea would be to scan post content of all the posts but it can be a pain for a big site having a large no of posts. I would do it by saving a serialized array of links of a post in its postmeta (for new & for existing) and then query this meta info from postmeta table and scan through and return a arry of post IDs which link to the post being deleted. You can either halt it or make it to take whatever action you want.– AshfameMay 10, 2011 at 11:36
-
@Ashfame: Interesting suggestion. Now if you would create a plugin for it...– Jan FabryMay 10, 2011 at 13:00
-
Another +1 plus a fav. @Jan Fabry & @Ashfame - I'm sure you want to work together on this one! :)– kaiserMay 10, 2011 at 17:31
-
@user3047 Don't you want to mark this one as solved?– kaiserSep 5, 2011 at 8:26
4 Answers
After reading this thread I saw that I might need this also sometimes. So here is the result:
The internal link checker plugin
It adds a meta box at your post edit screens that shows links to all posts who link internally to the currently displayed post. If you want to alter the output (add something for eg.), please use the provided filter. An example of how to use the filter can be found at the readme file.
The Plugin is GPL2 licensed. Maybe I'll also put it in the official repo to allow installation from inside your self hosted blog. Edit: Done.
...or at...
...or in our own
-
And thanks to @Drake for providing the sql query (please go & upvote his answer).– kaiserMay 10, 2011 at 18:18
-
A bit rough but kinda works. If you have multiple links in the same post it will show duplicates. Accepted solution.– user3047Sep 6, 2011 at 12:39
-
Thanks for the heads up. Wasn't aware of that. Will change in a future version.– kaiserSep 6, 2011 at 13:26
You can do a query like:
SELECT ID, post_title, post_date, post_content
FROM wp_posts
WHERE post_content
LIKE '%your-post-title%' ORDER BY post_date
to get all posts that linked that old post order by date.
There is no separate table or data structure that keeps post-to-post links, so the best way to do this is to search your posts for the URL of the post you want to delete. The search works on the HTML code of the post, so it will contain the full link, even if you don't see it in the visual editor.
Of course, you should also search through the pages, since they can also contain links to posts.
Another approach would be to use Google. If you search for link:http://example.com/2011/05/post-to-delete/
it will return all pages that link there. You can then also add site:example.com
to limit the results to only pages on your site. Of course, this will not be as up-to-date as a search in your own current database.
Just use Google's Webmaster tools - it has a specific page showing internal links.