I need a little more clarification on the default query for a specific custom post type url. I am learning how to use WP default functions and queries via Udemy. However, I feel like this little part I need either better clarification or confirmation from the community. In the video in Udemy, it uses the variable $query as an argument in a function in order to customize the default query for a custom post type. However, I do not see anywhere else in the training that shows where that variable comes from. Yet, somehow, we are still able to implement it as an object in order to look into it for other data points or to customize the default query for a custom post type.
function university_adjust_queries($query) {
if(!is_admin() && is_post_type_archive('program') && $query->is_main_query()){
$query->set('orderby', 'title');
$query->set('order','ASC');
$query->set('post_per_page', -1);
}
if(!is_admin() AND is_post_type_archive('event') AND $query->is_main_query()){
$today = date('Ymd');
$query->set('meta_key', 'event_date');
$query->set('orderby', 'meta_value_num');
$query->set('order','ASC');
$query->set('meta_query', array(
array(
'key' => 'event_date',
'compare' => '>=',
'value' => $today,
'type' => 'numeric'
)
));
}
}
add_action('pre_get_posts','university_adjust_queries');
Is this variable a default variable in the WordPress application that everyone is used to using or is it just something that was created on the fly?
If it is a default variable widely used by WP, then is this the key variable I can go to no matter what the custom post type or default post type is? Is it always stored in the same $query variable?
Is that the reason why the instructor decided to use it, although I can't see it anywhere else? Is it just common knowledge now?
Thank you
Editlink under the list of tags to edit your question and include the missing context