2

How can I generate a pretty permalink correctly for a post knowing the permalink structure?

My posts where processed with the FeedWordPress plugin with the "Link" setting set to "Permalinks point to: The copy on the original website".

So for all the posts in the admin area when editing a post the "Permalink" field under the post title shows an original, external site's URL, which is stored in the "syndication_permalink" meta data.

What I would like to do is to generate a pretty permalink for all such posts that would point to a local host (i.e. the post will have a permalink of type "http://mysite.com/" rather than have an external link to a source), so that I can update the permalinks in DB.

I can get the permalink structure using get_option('permalink_structure'). Is there a WP function that I can use to get a pretty permalink generated correctly for a post by its ID?

Hope that makes sense.

Thanks, Dasha

2
  • P.S. Maybe there is an easier way to "revert" posts from FeedWordPress into "local" posts?
    – dashaluna
    Jul 21, 2011 at 12:28
  • Updated the question, got confused with GUID and permalinks, as @Rarst mentioned they aren't the same thing.
    – dashaluna
    Jul 21, 2011 at 14:32

2 Answers 2

1

GUID and permalink are two completely independent things. GUIDs are usually based on permalinks, but they don't have to be. Permalinks are not based on GUIDs in any way in modern WP (it had been changed long ago).

If you permalinks are not being generated correctly then that plugin (or some other) is breaking something in a bad way, it is unrelated to what your GUIDs contain.

2
  • thanks a lot for the answer. The plugin generated links correctly, making the permalink of posts to be original, external links. Now, however, I need to make them point to local posts, so that posts' permalinks will be of type "mysite.com/<permalink_structure>". I don't know how I can generate a pretty permalink for a post by its ID. I was hoping I can, so then I can update the permalink for that post in the DB from external to local.
    – dashaluna
    Jul 21, 2011 at 14:27
  • @dashaluna are you talking about links to the posts or links in the post content? Also see get_permalink() which is what you are asking literally here, but I am not sure if that is what you need.
    – Rarst
    Jul 21, 2011 at 15:25
0

The permalinks are not something that's "generated" per se... they're something that's parsed to point to a certain post.

If you imported posts using FeedWordPress, FeedWordPress doesn't do anything to actually change your permalink... it just creates a post meta field called 'syndication_permalink' that it then uses to filter functions like get_permalink etc. If you delete that meta field or remove the filter (ie disabling the plugin), then functions like get_permalink will point to the local post.

Alternately, FWP includes a function for getting the local permalink. Try calling get_local_permalink( $post_ID ) for that.

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.