5 most important tips and trick for wordpress post

The most appropriate use for get_posts is to create an array of posts based on a set of parameters. It retrieves a list of latest posts or posts matching the criteria. If you would like to alter the main query before it is executed, you can hook into it using pre_get_posts.

If you would just like to call an array of posts based on a small and simple set of parameters within a page, then get_posts is your best option.


How to Displays Random Posts

Create a custom template page and simply paste this snippet there:

Latest posts ordered by title

Use below code to show the latest ten posts sorted alphabetically in ascending order. The following code will display their post date, title and post descriptions:

Show attachments for the current post

Use the below code inside the wordpress loop function:

Get a post by its slug

If you want to get the slug of your recent post,then simply copy & paste this code:

Access all post data

Want to access all post’s data including the attachments,description,title,date,featured images etc. use the below code. This is resolved by calling an internal function setup_postdata(), with the $post array as its argument:

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Article Tags: , , , , , , ,