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()– Returnstrueif the current page is a 404 error page.is_admin()– Returnstrueif the current page is an admin page.is_archive()– Returnstrueif the current page is an archive page.is_attachment()– Returnstrueif the current page is an attachment page.is_author()– Returnstrueif the current page is an author archive page.is_category()– Returnstrueif the current page is a category archive page.is_comments_popup()– Returnstrueif the current page is a comments popup window.is_date()– Returnstrueif the current page is a date archive page.is_day()– Returnstrueif the current page is a day archive page.is_feed()– Returnstrueif the current page is a feed page.is_front_page()– Returnstrueif the current page is the front page.is_home()– Returnstrueif the current page is the home page.is_month()– Returnstrueif the current page is a month archive page.is_page()– Returnstrueif the current page is a page.is_paged()– Returnstrueif the current page is paginated (returns only true starting on the 2nd page onwards, not the first).is_preview()– Returnstrueif the current page is a preview page.is_search()– Returnstrueif the current page is a search results page.is_single()– Returnstrueif the current page is a single post page.is_singular()– Returnstrueif the current page is a singular page (page, post, or attachment).is_tag()– Returnstrueif the current page is a tag archive page.is_tax()– Returnstrueif the current page is a taxonomy archive page.is_time()– Returnstrueif the current page is a time archive page.is_trackback()– Returnstrueif the current page is a trackback page.is_year()– Returnstrueif 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