Will I see a performance hit if I use native API calls like get_the_title() instead of $post->post_title?

Template tags rely on global $post (unless you explicitly provide something else to those that support it. So either:

  • they get something from that variable (no reason to go for it in database)

  • or they don’t (then they fail because they have no clue what you want)

Under most normal circumstances there is no reason to worry about impact of template tags. That only comes into play if you start dealing with crazy amount of posts and/or apply overly complex filters.

Update after discussion in comments

get_post() always tries to invoke cache before it makes database call. Cache gets purged by functions that modify posts explicitly ( see clean_post_cache() ) or expires naturally.

Leave a Comment