I'm running the following PHP Code Sniffs on some WordPress code, and the following warning pops up
352 | WARNING | get_posts is discouraged in favor of creating a new
| | WP_Query() so that Advanced Post Cache will cache
| | the query, unless you explicitly supply
| | suppress_filters => false.
While I'm an experienced programmer, I'm not super familiar with WordPress's history. This warning seems important, but is awkwardly worded. I'm confused on a few points, and other answers I've found on the subject don't seem to address my points.
What is the "Advanced Post Cache". I know WordPress (like a lot of PHP applications) has caching going on at a few different levels.
Is this warning telling me that
get_posts
will never use the cache, butWP_Query
will?Is this warning telling me that using
suppress_filters
withWP_Query
will bypass the Advanced Post Cache? Or that usingsuppress_filters
withget_posts
will invoke the cache? Or something else?What else does
suppress_filters
do?
If someone more familiar with the matter could clue in a WordPress newb I'd appreciate it. I'm not looking for a "always use X, or never use Y" sort of answer -- I'm trying to understand the tradeoffs of each approach.
WP_Query
, it's whatget_posts
uses internally. Also as an aside, never usequery_posts
under any circumstances, and always remember to cleanup withwp_reset_postdata