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.

wordpress-logo

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 founder of freewebmentor.com and Software developer from New Delhi (India). Follow Prem's development codes on facebook, and make sure you check out freewebmentor.com for the latest in web development related Tips with the complete code.


You may also like:

Follow us!

Get Free Access of 350+ Scripts

Don't worry you'll not be spammed!

Featured eBook

WordPress Security Guide

Learn how to implement security guideline in your WordPress site...

DOWNLOAD

Pincode Finder

pincode-finder tool

Online Pincode Finder

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

SEARCH NOW