Created
February 2, 2015 08:27
-
-
Save musen/00ba40aa5edf4fc151c2 to your computer and use it in GitHub Desktop.
Wordpress pre_get_posts action hook. Comes in handy when you would like to modify query variables before running archive queries.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//order products alphabetically and display all of them | |
function prefix_products_archive_modify( $query ) { | |
if ( is_post_type_archive('product') && | |
! empty( $query->query['post_type']) && | |
$query->query['post_type'] == 'product') { | |
$query->set( 'orderby', 'title' ); | |
$query->set('order', 'ASC'); | |
$query->set( 'posts_per_page', -1 ); | |
} | |
return $query; | |
} | |
add_action( 'pre_get_posts', 'prefix_products_archive_modify' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment