How to obtain the author and classification information of articles in WordPress
This article mainly introduces how to obtain the author and classification information in WordPress, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
Author
To query articles related to some authors (users), you can use four parameters:
Author (integer): user ID
Author_name (string): nickname of the user ("user_nicename" field)
Author__in (array): user ID
Author__not_in (array): user ID
Get an author's article
Obtain according to the user ID:
$query = new WP_Query ('author=123')
Based on the user's nickname ("user_nicename" field):
$query = new WP_Query ('author_name=rami')
Get articles from multiple authors
Get the articles of multiple authors based on the user ID:
$query = new WP_Query ('author=2,6,17,38')
Exclude the author's article
Rule out the way an author can use the user ID preceded by a "-":
$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 five parameters available for classification:
Cat (integer): classification ID
Category_name (string): classification alias
Category__and (array): classification ID
Category__in (array): classification ID
Category__not_in (array): classification ID
Get a classified article
Get a classified article based on the classified ID (including the subcategories of this category):
$query = new WP_Query ('cat=4')
Get a classified article based on the alias of the category (including the subcategories of this category):
$query = new WP_Query ('category_name=staff')
Get a classified article based on the classified ID (excluding the subcategories of this category):
$query = new WP_Query ('category__in=4')
Get multiple classified articles
Get multiple classified articles based on the classified ID:
$query = new WP_Query ('cat=2,6,17,38')
Get multiple classified articles based on classification aliases:
$query = new WP_Query ('category_name=staff,news')
Get articles that have several categories at the same time according to the category alias:
$query = new WP_Query ('category_name=staff+news')
Exclusion classification
To exclude some categories, you just need to precede the category ID with a "-" sign:
$query = new WP_Query ('cat=-12,-34,-56')
Multi-classification query
To get articles with multiple categories at the same time, the following code gets articles that must have categories with ID 2 and 6 at the same time:
$query = new WP_Query (array ('category__and' = > array (2,6))
Get articles with multiple categories, excluding their subcategories. The following code gets articles with an ID of 2 or an ID of 6:
$query = new WP_Query (array ('category__in' = > array (2,6))
Exclude some classified articles:
$query = new WP_Query (array ('category__not_in' = > array (2,6)); Thank you for reading this article carefully. I hope the article "how to get the author and classified information in WordPress" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!