query coding for pre_get_posts Hook
-
Good evening –
I’ve been following along a textbook and have come to a point where I’m learning to use the pre_get_posts “hook” function to change the sort order of “the loop.” Most of the examples are with a single query criteria – but I need two in order to sort by “date” in “ASC” order. To accomplish this I’ve included the following function in my functions.php
<?php
function my_sortem( $query ) {
$query->set( ‘orderby’, ‘date’ );
$query->set(‘order’, ‘ASC’);
}
add_action( ‘pre_get_posts’, ‘my_sortem’ );This works just fine – as I followed an example using multiple query criteria.
My question is trying to understand exactly what’s happening with the syntax:
$variable->set( ‘criteria’, ‘value’);
Oddly, there’s almost nothing about the “set()” function in on-line info.
I can’t tell if in my example if “$query” is an object or an array. I’m pretty sure it’s an array, as an object would require the “=>” operator.
But I haven’t found any reference to the “set()” in regards to arrays in PHP.
Can someone please point me in the right direction so I properly understand this code syntax? Many Thanks!
- The topic ‘query coding for pre_get_posts Hook’ is closed to new replies.