Last active
May 4, 2018 17:33
-
-
Save uncatcrea/c4489844129ad86ffa9f to your computer and use it in GitHub Desktop.
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
<?php | |
// Write the following in a WP plugin of yours | |
// or in the php directory of your WP-AppKit theme. | |
/** | |
* For this example we use the "wpak_posts_list_query_args" hook | |
* to customize the query to sort the posts of our | |
* "my-component-slug" component by alphabetical order. | |
* | |
* Internally the component's query is a WP_Query object: see | |
* https://codex.wordpress.org/Class_Reference/WP_Query | |
* to have an overview of all the taxonomies/meta ordering/filtering possibilities. | |
*/ | |
function my_custom_query( $query_args, $component ) { | |
if( $component->slug === 'my-component-slug' ) { | |
$query_args['orderby'] = 'name'; | |
$query_args['order'] = 'ASC'; | |
//see https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters | |
} | |
return $query_args; | |
} | |
add_filter( 'wpak_posts_list_query_args', 'my_custom_query', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment