Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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