Use of PHP functions used for obtaining recent articles in WordPress development. _ PHP Tutorial

Source: Internet
Author: User
In WordPress development, PHP functions used to obtain recent articles are parsed ,. In WordPress development, PHP functions used to obtain recent articles are parsed. the wp_get_recent_posts function is a function in WordPress that can obtain arrays of recent articles, compared with other PHP functions used in WordPress development to obtain recent articles,

The wp_get_recent_posts function is a function in WordPress that can obtain the array of recent articles. compared with other methods, wp_get_recent_posts returns an array instead of an object, therefore, it may be more convenient for new users or lazy people to use. let's explain this function as an example.

The English explanation is very short, so I will not post it,
Obtain the function of the latest article.
In fact, this is another use of the get_posts function.
The description can be used in a good way.


 <?php   wp_get_recent_posts( $args )  ?>

Default value

<? Php $ args = array (// Number of articles Retrieved 'numberposts' => 10, // Obtain the 'offset' => 0 from the first few articles, // The Category ID, if this parameter is not set, 'category' => 0 is displayed for all categories, // sorting rules (note 1, Details) 'orderby' => 'Post _ date ', // sort 'order' => 'desc' in ascending or descending order, // include the article ID 'include' =>, // exclude article ID 'exclude' =>, // the custom field name 'meta _ key' =>, // The value of the custom field. in combination with the previous parameter, select an article that matches the custom field value. 'Meta _ value' =>, // Article type: article or page 'post _ type' => 'post', // Article status: draft, published, and hidden articles .... 'Post _ status' => 'Draft, publish, future, pending, private', // This wood study 'SS Ress _ filters '=> true);?>

Because it is similar to get_posts,
Therefore, we will not give any advanced examples, but simply give an official example.

Recent Posts
    <? Php // Get the latest article $ recent_posts = wp_get_recent_posts (); // traverse each article. Foreach ($ recent_posts as $ recent) {echo'
  • '. $ Recent ["post_title"].'
  • ';}?>

Note: Because the return value of the wp_get_recent_posts function is an array,
In theory, the setup_postdata function can only accept variables of the object type,
Therefore, according to the official documentation, the setup_postdata function cannot be used to load data to the loop.
I didn't try it because I didn't use much. if you are interested, you can try it out.
Therefore, if you use the setup_postdata function,
The wp_get_recent_posts function is not as convenient as the get_posts function.

'Author' -- sort by author value
'Category '-- sort by category value
'Content' -- sort by content
'Date' -- sort by creation date
'Id' -- sort by document number
'Menu _ order' -- sort by menu order. Only available on pages.
'Mime _ type' -- sort by mime type. Only attachments are available.
'Modified' -- sort by the last modification time.
'Name' -- Sort By stubs.
'Parent' -- sort by parent ID
'Password' -- sort by password
'Rand' -- any sorting result
'Status' -- sort by status
'Title' -- sort by title
'Type' -- sort by type

Articles you may be interested in:
  • Introduction to using custom menu related PHP functions in WordPress development
  • Use of PHP functions used to retrieve search forms in WordPress
  • Use the wp_count_posts function in WordPress to count the number of articles
  • Detailed description of PHP functions that call comment templates and output comments cyclically in WordPress
  • Simple steps to add the Google search function to WordPress
  • Details on the use of the get_post and get_posts functions in WordPress development
  • Parse post_class and get_post_class functions in WordPress
  • Using the get_post_custom () function in WordPress development
  • Install and use the video Player plug-in Hana Flv Player in WordPress
  • The use of the wp_list_categories function in WordPress
  • Implementation of short code in WordPress development and related function usage skills

Functions, wp_get_recent_posts function is a function in WordPress that can obtain the array of recent articles, compared with other functions...

Related Article

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: 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.