Gets entries (posts, pages, attachments) from the database by specified criteria. You can select any posts and sort them any way you want.
This is a wrapper for the
WP_Query class, i.e. the function understands all
Get_posts() has preset parameters. These sometimes need to be changed so that they don’t interfere with the desired result. Preset parameters:
post_type = post— if we specify the taxonomy output for a record type other than post, then the post_type parameter should be changed — by default it is post.
numberposts = 5— If we forget to change the numberposts parameter, we may wonder why only 5 records are displayed instead of the necessary 20.
suppress_filters = true— this parameter disables some filters (hooks).
get_posts() is an analog of
query_posts(). The difference is that
get_posts() does not interfere with WP global query, but creates a separate instance of WP_Query class.