0
0
Wordpressframework~5 mins

Custom post type queries in Wordpress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a custom post type in WordPress?
A custom post type is a content type you create to organize and display different kinds of content beyond the default posts and pages, like portfolios, products, or events.
Click to reveal answer
beginner
Which WordPress function is used to query custom post types?
The <code>WP_Query</code> class is used to query custom post types by setting the <code>post_type</code> parameter to the custom post type's name.
Click to reveal answer
intermediate
How do you query multiple custom post types at once?
You pass an array of post type names to the post_type parameter in WP_Query, like ['book', 'movie'].
Click to reveal answer
intermediate
What parameter do you use to order custom post type query results by a custom field?
Use meta_key to specify the custom field and orderby set to meta_value or meta_value_num in WP_Query.
Click to reveal answer
advanced
Why should you use pre_get_posts action when modifying main queries for custom post types?
Because it lets you safely modify the main query before it runs, ensuring your custom post type content shows up correctly without breaking other queries.
Click to reveal answer
Which parameter in WP_Query specifies the custom post type to query?
Apost_type
Bpost_status
Cpost_category
Dpost_author
How do you query both 'book' and 'movie' custom post types together?
Apost_type => 'book,movie'
Bpost_type => 'all'
Cpost_type => 'book|movie'
Dpost_type => ['book', 'movie']
Which WP_Query parameter orders results by a custom field's numeric value?
Aorderby => 'title'
Borderby => 'meta_value_num'
Corderby => 'date'
Dorderby => 'author'
What hook lets you modify the main query before it runs?
Ainit
Bwp_head
Cpre_get_posts
Dtemplate_redirect
If you want to show only published custom posts, which parameter do you set?
Apost_status => 'publish'
Bpost_status => 'draft'
Cpost_status => 'pending'
Dpost_status => 'private'
Explain how to create a query for a custom post type called 'event' that orders results by a custom date field.
Think about how to tell WP_Query which post type and custom field to use for sorting.
You got /5 concepts.
    Describe why and how you would use the pre_get_posts hook when working with custom post type queries.
    Consider how to change what WordPress shows on archive or home pages.
    You got /4 concepts.