WordPress.org

Support

Support » Plugins and Hacks » help: need to append text to content and excerpt

help: need to append text to content and excerpt

  • dirkhaim
    Member

    @dirkhaim

    I am trying to build an automization flow for a WordPress photo blog, and for that I want to add text to both the content and the excerpt of a post once it’s saved. I managed to hook my plugin to the save event, and now I need to add the text to both fields.

    Is there an API for that or do I need to write into the database? how do I do that?

    I want to keep it as compatible with the API as possible, so I can upgrade WP later with no problem.

    I am quite new to writing plugins, but I do have programming experience.

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Andrew Ozz
    WordPress Dev

    @azaozz

    dirkhaim
    Member

    @dirkhaim

    first I tried to hook an action to post_save, but there I had a problem using wp_post_update. I created a loop, so it’s not good.

    My second approach as to use filters, so I decided to I will modify the content by using the content_save_pre hook, but there I don’t have the post ID and I have no access to the custom fields, from which I need to take data.

    I am kind of stuck.

    Any one can direct me to the best solution?

    Thanks

    Andrew Ozz
    WordPress Dev

    @azaozz

    Wouldn’t it be better if you append your text on runtime – that way you can change it later, as it’s not saved in the db with the post. You can use filters: the_content, the_content_rss, the_excerpt, the_excerpt_rss, etc. to attach a string where you need it.

    dirkhaim
    Member

    @dirkhaim

    no, because I call a python script to resize images and create set of images in different size for each photo

    it’s a lot of work, and I don’t really need it to happen everytime

    dirkhaim
    Member

    @dirkhaim

    I actually solved the issue by using wpdb->query to append the text to the content and excerpt

    still, I would rather have an API function to do this

    Hi dirkhaim,
    could you provide some more detail on how you used $wpdb->query to append text onto the content?

    I’m trying to do the same thing and would like to avoid re-inventing the wheel if possible.. thanks!

    Sorry, but that was a while ago. Since then I changed the code to it on runtime and I don’t remember how I did it. Basically you can find out how to do it by reverse engineering the post save flow.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘help: need to append text to content and excerpt’ is closed to new replies.