Get_posts () function wordpress Call Specify ID article multiple articles

Source: Internet
Author: User

WordPress built-in function get_posts () is used to invoke the specified one or more articles, the function provides several parameters, you can set the invocation of the article of the specified classification, custom fields, article type, article status, display order and other conditions, the article is returned as an array, the output can be through the loop statement.

Code structure:

1
<?php get_posts ($args);? >

Returns the variable of the array type, $args is the necessary variable for the function

Variable $args parameter:

1234567891011121314151617181920212223242526272829303132333435363738394041
<?php $args = Array (    //number of articles displayed    ' numberposts ' = +//     with the    first article as the starting position    ' offset ' =          0,    //Call the category ID, multiple separated by commas, or pass a numbered array, you can specify multiple classification numbers.       ' category '        = +,    //article Sorting rules ' ORDER BY '    = ' post_date '         ,    //Ascending, descending ' ASC '--ascending (low to high)  ' desc '--descending (high to bottom)    ' order '           = ' DESC ',    //To show the article ID    ' include ' and    //To exclude the ID of the article    ' Exclude ' +         ,    //custom field name    ' Meta_key ' +        ,    //custom field value, with previous parameter, To select an article that displays values that match a custom field.    ' Meta_value ' +      ,    //post (log)-Default, page (pages), attachment (attachment), any--(All)    ' post_type '       = > ' post ',    //MIME type of the article    ' post_mime_type '  = =/    /To display the article's parent ID    ' post_parent '     = ,    //Article Status    ' post_status '     = ' publish ');? >

Ordered by order optional values:

    • ' Author '--Sort by author numeric number
    • ' Category '--Sort by category numeric number
    • ' Content '--Sort by content
    • ' Date '--Sort by creation date
    • ' ID '--Sort by article number
    • ' Menu_order '--Sort by menu order. Only pages are available.
    • ' Mime_type '--Sort by MIME type. Only attachments are available.
    • ' Modified '--sort by last modified time.
    • ' Name '--sort by stub.
    • ' Parent '--Sort by Parent ID
    • ' Password '--Sort by password
    • ' Rand '--any sort of result
    • ' Status '--Sort by status
    • ' title '--Sort by title
    • ' Type '--Sort by type

Example: calling four articles with the specified ID 1,3,4,6

1234567891011121314
<?php $posts = get_posts ("numberposts=4&post_type=any&include=1,3,4,6"); if ($posts): foreach ($posts as $post): Setup_postdata ($post);? ><li>

Get_posts () function WordPress calls the specified ID article multiple articles

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.