Last Updated on: 21st February 2023, 11:05 pm
Lately I have been playing around with pre_get_posts
much and wanted to know all kinds of query types one can use to form a conditional statement. I did not find a good list, so I created my own.
Here are the WordPress query types that I found exist, along with their corresponding is_
functions:
is_404()
– Returnstrue
if the current page is a 404 error page.is_admin()
– Returnstrue
if the current page is an admin page.is_archive()
– Returnstrue
if the current page is an archive page.is_attachment()
– Returnstrue
if the current page is an attachment page.is_author()
– Returnstrue
if the current page is an author archive page.is_category()
– Returnstrue
if the current page is a category archive page.is_comments_popup()
– Returnstrue
if the current page is a comments popup window.is_date()
– Returnstrue
if the current page is a date archive page.is_day()
– Returnstrue
if the current page is a day archive page.is_feed()
– Returnstrue
if the current page is a feed page.is_front_page()
– Returnstrue
if the current page is the front page.is_home()
– Returnstrue
if the current page is the home page.is_month()
– Returnstrue
if the current page is a month archive page.is_page()
– Returnstrue
if the current page is a page.is_paged()
– Returnstrue
if the current page is paginated (returns only true starting on the 2nd page onwards, not the first).is_preview()
– Returnstrue
if the current page is a preview page.is_search()
– Returnstrue
if the current page is a search results page.is_single()
– Returnstrue
if the current page is a single post page.is_singular()
– Returnstrue
if the current page is a singular page (page, post, or attachment).is_tag()
– Returnstrue
if the current page is a tag archive page.is_tax()
– Returnstrue
if the current page is a taxonomy archive page.is_time()
– Returnstrue
if the current page is a time archive page.is_trackback()
– Returnstrue
if the current page is a trackback page.is_year()
– Returnstrue
if the current page is a year archive page.
These functions can be used in conjunction with conditional statements to customize the output of your WordPress site based on the current query. For example:
if ( is_home() ) {
// Display something on the home page
}
elseif ( is_single() ) {
// Display something on a single post page
} else {
// Display something else on all other pages
}
Note that not all query types will apply to every page of your WordPress site, depending on your site’s content and organization.
Leave a Reply