The method of using WordPress to get the author and classified information of the article _php example

Source: Internet
Author: User
Author
Query and some author (user) related articles, you can use 4 parameters:

    1. Author (integer): User ID
    2. Author_name (String): User's nickname ("User_nicename" field)
    3. Author__in (array): User ID
    4. Author__not_in (array): User ID

Get an article from an author

Get by User ID:

$query = new Wp_query (' author=123 ');

Based on the user's nickname (the "User_nicename" field) gets:

$query = new Wp_query (' Author_name=rami ');

Get articles from multiple authors

Get articles from multiple authors based on user ID:

$query = new Wp_query (' author=2,6,17,38 ');

Exclude author's articles

Exclude an author can use the user ID to precede the "-" way:

$query = new Wp_query (' author=-12 ');

Multi-author Query

Get articles from multiple authors:

$query = new Wp_query (Array (' author__in ' = = = Array (2, 6)));

Exclude articles from multiple authors:

$query = new Wp_query (Array (' author__not_in ' = = = Array (2, 6)));

Classification

There are 5 parameters available for classification:

    1. Cat (integer): Category ID
    2. Category_name (String): Category Alias
    3. Category__and (Array): Category ID
    4. Category__in (Array): Category ID
    5. Category__not_in (Array): Category ID

Get a categorized article

Get a categorized article (containing subcategories of this classification) based on the ID of the category:

$query = new Wp_query (' cat=4 ');

Get a categorized article (containing subcategories of this classification) based on the alias of the classification:

$query = new Wp_query (' Category_name=staff ');

Get a categorized article based on the ID of the category (it does not contain subcategories for this classification):

$query = new Wp_query (' category__in=4 ');

Get Articles with multiple classifications

Get more than one categorized article based on the ID of the category:

$query = new Wp_query (' cat=2,6,17,38 ');

Get multiple categories of articles based on classification aliases:

$query = new Wp_query (' category_name=staff,news ');

Get articles that have several categories at the same time based on classification aliases:

$query = new Wp_query (' category_name=staff+news ');

Exclude Categories

To exclude some categories, just precede the category ID with the "-" number:

$query = new Wp_query (' cat=-12,-34,-56 ');

Multi-category Query

To get an article with multiple classifications at once, the following code gets an article that must have a category with IDs 2 and 6 at the same time:

$query = new Wp_query (Array (' category__and ' = = = Array (2, 6)));

Get Articles with multiple classifications, without their subcategories, and the following code gets an article with an ID of 2 or a category with ID 6:

$query = new Wp_query (Array (' category__in ' = = = Array (2, 6)));

To exclude some classified articles:

$query = new Wp_query (Array (' category__not_in ' = = = Array (2, 6)));
  • 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.