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 (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:
- 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 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)));