Category, Tag, and Author Parameters in WordPress
Categories all the posts in WordPress and Posts can also be sorted by the category into which they were placed, by tags applied to the post, or by the author information author means which is written the psot for example this article is Written by Web Design Agency London:
➤ cat=2, 6, 8 — Here the key word cat it Load posts based on category ID which has 2, 6 and 8.
➤ category_name= Web Design London — Which are in this category Web Design London it Loads all the posts it based on category name. Remember that if a post belongs to more than one category, then it will show up in selections for each of those categories.
➤ tag=design — It loads all the posts that is based on tag name design.
➤ tag_id=57 — It loads all the posts that is based on tag ID and here tag id is 57.
➤ author=1 — It loads all the posts that is based on the author ID.
➤ author_name=intylestyle — It loads all the posts that is based on author’s name here is intylestyle.
Date, Time, Ordering, and Custom in WordPress
Parameters to select the content based on their chronology are a key part of building an archive of posts, or providing a view into content through a calendar on your blog’s homepage. Another option is that you can also change the sort parameter and the sort order of the posts. If you’re creating online posts, and you want to show the post listing as alphabetical order on your web site, then you’ll set the parameters for querying posts by month and author, but the post order results by title.
➤ monthnum=2 — It loads the posts which is created in the month of June.
➤ day=6 — It loads the posts which is created on the 6th day of the month.
➤ year=2013 — It loads the posts which is created in the year of 2013.
➤ orderby=title — It is the Field to order posts by the title.
➤ order=ASC — It defines the ascending or descending order of orderby of post.
➤ meta_key=color — It loads the posts by custom field name.
➤ meta_value=blue — It loads the posts by custom field value. It must be used in conjunction with the meta_key parameter that tells you above.
Now putting It together then look at some examples using parameters.
The following examples use the $letestPosts->query() function from the $letestPosts custom query object created in the example to select the content displayed in your custom Loop.
Display post based on post ID:
$letestPosts = new WP_Query( ‘p=1’ );
Here display the six latest posts and skipping the first post:
$letestPosts = new WP_Query( ‘posts_per_page=6&offset=1’ );
If you want to display all the posts from today: // display all posts from the current date
Then getdate(); // get todays date is a function that get current date
$todaydate = getdate(); // get todays date
$myPosts = new WP_Query(‘year=’ .$ todaydate [“year”].’&monthnum=’ .$ todaydate [“mon”] .’&day=’ .$ todaydate [“mday”] );
If you want to display all posts from category ID 7 with the intylestyle tag:
$myPosts = new WP_Query( ‘cat=7&tag=intylestyle’ );
If you want to display all posts with the intylestyle tag, and excluding posts in category ID 7:
$myPosts = new WP_Query( ‘cat=-7&tag=intylestyle’ );
If you want to display all posts with the tags writing and reading and webdesing:
$myPosts = new WP_Query( ‘tag=writing+reading+ webdesing’ );
If you want to display all posts with a custom field named color with a value of red:
$myPosts = new WP_Query( ‘meta_key=color&meta_value=red );