A method for obtaining the author and classification information of the article in WordPress to collate _php instances

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 ("User_nicename" field), get:

$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 article

Exclude an author from using the "-" method in front of the user ID:

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

Multiple author queries

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 an article in a category

Gets a categorized article (a subcategory that contains this category) based on the ID of the category:

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

Gets a categorized article (a subcategory that contains this category) based on the alias of the category:

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

Gets a categorized article based on the ID of the category (a subcategory that does not contain this category):

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

Get Articles for multiple categories

Get multiple categories of articles based on the ID of the category:

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

To get multiple categories of articles based on a category alias:

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

Get articles that have several categories at the same time based on the category alias:

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

Exclude classification

To exclude some categories, you only need to precede the category ID with the "-" sign:

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

Multi-Classification Query

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

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

Gets multiple categories of articles that do not contain subcategories, and the following code gets an article with a category with ID 2 or ID 6:

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

Exclude some categories of 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.