WordPress.org

Ready to get started?Download WordPress

Forums

help: need to append text to content and excerpt (8 posts)

  1. dirkhaim
    Member
    Posted 6 years ago #

    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

  2. Andrew Ozz
    WordPress Dev
    Posted 6 years ago #

  3. dirkhaim
    Member
    Posted 6 years ago #

    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

  4. Andrew Ozz
    WordPress Dev
    Posted 6 years ago #

    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.

  5. dirkhaim
    Member
    Posted 6 years ago #

    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

  6. dirkhaim
    Member
    Posted 6 years ago #

    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

  7. eliotc
    Member
    Posted 6 years ago #

    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!

  8. dirkhaim
    Member
    Posted 6 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic