Author
Query and some author (user) related articles, you can use 4 parameters:
- Author (integer): User ID
- Author_name (String): User's nickname ("User_nicename" field)
- Author__in (array): User ID
- 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:
- Cat (integer): Category ID
- Category_name (String): Category Alias
- Category__and (Array): Category ID
- Category__in (Array): Category ID
- 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));