PHP functions used to obtain recent articles in WordPress development using analytic _php techniques

Source: Internet
Author: User

The Wp_get_recent_posts function in WordPress is a function to get an array of recent articles, compared to other articles, Wp_get_recent_posts returns an array instead of an object, So in the use of some novice or lazy people, may be more convenient, let us explain this function on the example.

Describe
wp_get_recent_posts
The English explanation is very short, will not post,
The Chinese probably means: get the function of the latest article.
In fact, this is a get_posts function.
The description of the again good wood used, see below to use.

Usage/usage

 <?php 
  wp_get_recent_posts ($args) 
 ?>

Parameter Default value

 <?php $args = Array (
//Get number of articles
  ' numberposts ' =>,//
starting from the first few get
  ' offset ' => 0,
//category ID, If not set then show all categories
  ' category ' => 0,
////collation (note 1, under detail)
  ' by ' => ' post_date ',
//L, descending sort
  ' order ' = > ' DESC ',//
included article ID
  ' include ' =>,
//excluded Article ID
  ' Exclude ' =>,//
custom field name
  ' Meta_ Key ' =>,
//The value of the custom field, with the previous argument, to select the article to display the value of the custom field.
  ' Meta_value ' =>,
//Article type: Article or page
  ' post_type ' => ' post ',
//Post Status: Draft, posted, hidden article ...
  ' Post_status ' => ' draft, publish, future, pending, Private ',
//This wood study
  ' suppress_filters ' => true); 
? >

Instance
because it's very similar to the way get_posts is used,
So don't give any advanced examples, simply give an official example.

 
 

Summarize
Note: Because the return value of the Wp_get_recent_posts function is an array,
The Setup_postdata function can theoretically only accept variables of the object type,
So the official document explains that you can't use the Setup_postdata function to load into a loop.
Because the use of not much, so I have not to try, interested students can try to see whether the success.
So, if you use the Setup_postdata function,
The Wp_get_recent_posts function is not as easy to use as the Get_posts function.

Note:
' Author '--Sorting by author numeric number
' Category '--sorting by category numeric number
' Content '--Sort by contents
' Date '--sorted by creation date
' ID '--Sort by article number
' Menu_order '--sorted by menu order. Only pages are available.
' Mime_type '-Sort by MIME type. Only attachments are available.
' Modified '--sorted by last modified time.
' Name '--sort by stub.
' Parent '--Sort by Parent ID
' Password '--Sort by password
' Rand '--arbitrary sort result
' Status '--sorted by state
' title '--Sort by title
' Type '--Sort by type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.