5 most important tips and trick for wordpress post

| Last Updated: | In: WP Labs

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:

Tags: , , , , , , ,

About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby.

You may also like:

Follow us!

Get Free Access of 400+ Scripts

Don't worry you'll not be spammed!

Featured eBook

WordPress Security Guide

Free Guide: Learn how to implement security guideline in your WordPress site...


Pincode Finder

pincode-finder tool

Online Pincode Finder

Best tool to locate post Office address and pincodes of all india...