• I have a very simple custom plugin I’ve written which dynamically adds scheduled/published posts to a separate forum on my site (non-Wordpress forum). In other words, a writer posts an article, and the article in turn is posted to our forum.

    I’d like to be able to “grab” the link created by the forum, and link it from within my wordpress post, from this same plugin. Assuming I’m already able to get that link from within my plugin, how can I go about adding it to the bottom of my post?

    • This topic was modified 9 years, 4 months ago by kflavin21.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Can you be more specific about where the trouble is occurring? Are you having trouble associating the link with the correct post? Are you unsure of how to modify your theme?

    Thread Starter kflavin21

    (@kflavin21)

    I was trying to figure out the best way to store the data, retrieve it, and then display it in the template.

    I think I found what I was looking for though:
    https://codex.ww.wp.xz.cn/Function_Reference/add_post_meta

    It looks like I can just add my URL as metadata for each post, and retrieve it for display on my theme.

    One question – when a post is deleted, does all associated metadata get removed, or do I need to handle removing any metadata I add?

    Yes, there is a good chance saving the link as custom post meta is what I would do as well.

    Also, yes, my understanding is that when a post is deleted (not trashed), the associated meta gets deleted with it.

    Moderator bcworkz

    (@bcworkz)

    I can confirm the meta data is deleted with the post as long as the WP admin screens are used to delete, or the wp_delete_post() function is used. If the post is deleted by some other shortcut method, the meta data would likely stay.

    Also removed are related comments, revisions, and assigned taxonomy terms.

    Oh one more little thing. Be sure to give update_post_meta() a look as well. I often prefer using that over add_post_meta() to avoid duplicate meta key/values.

    https://codex.ww.wp.xz.cn/Function_Reference/update_post_meta

    Thread Starter kflavin21

    (@kflavin21)

    Great, thanks! I’ve been able to get something going – good to know I’m on the right track.

    I’ll check out using update_post_meta() as well. I think that makes sense for my situation.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Adding external, dynamically created links to posts’ is closed to new replies.