• Is there any possible way to hook to the get_post() function and modify the post object?
    I looked into the code of the get_post() function as well as the related functions of the WP_Post class, but couldn’t find any filter hooks.

    The reason why I need this is because I’m currently writing a multilingual plugin and I basically need to be able to automatically change the title/content/slug of posts. I can achieve that when the user is querying multiple posts by using the appropriate filters, but I simply can’t find any for get_post() in particular.

    Thanks for your time,
    Nikola

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Not the function itself, you would have to look at what is calling the function. Another possibility, rather “hacky”, not sure how well it would work, but the post object should get put into the cache, you may get away with manipulating that copy and putting it back into the cache.

    Start by looking at the get_instance() method of WP_Post class. It is called as part of the get_post() process.

    Thread Starter Nikola Nikolov

    (@nikolovtmw)

    Yep – basically that’s what I looked into(not the cache, but WP_Post::get_instance()) and couldn’t find any filters there.

    And the thing is that(at least I) you will just call get_post().

    Oh well – I’ll hook to whatever I can and if something gets through, I’ll tell people how to fix it 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Filter WP_Post object returned from get_post()’ is closed to new replies.