Last active
August 29, 2015 13:56
-
-
Save billerickson/9250280 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 | |
//* Add sorting buttons | |
add_action('genesis_before_loop', 'ac_sort_buttons'); | |
function ac_sort_buttons() { | |
echo '<p>'; | |
echo 'Sort:'; | |
echo '<a href="?sort=oldest">Oldest</a>'; | |
echo '<a href="?sort=alpha">Alphabetical</a>'; | |
echo '<a href="?sort=random">Random</a>'; | |
echo '<a href="?sort=all">Show All</a>'; | |
echo '</p>'; | |
} |
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 | |
/** | |
* Dynamic Sorting | |
* | |
*/ | |
function ac_dynamic_sort_films( $query ) { | |
if ( $query->is_main_query() && !is_admin() && $query->is_post_type_archive( 'films' ) ) { | |
if ( isset($_GET['sort']) && $_GET['sort'] == 'oldest' ) { | |
$query->set( 'order', 'DESC' ); | |
} | |
if ( isset($_GET['sort']) && $_GET['sort'] == 'alpha' ) { | |
$query->set( 'orderby', 'title' ); | |
} | |
if ( isset($_GET['sort']) && $_GET['sort'] == 'random' ) { | |
$query->set( 'orderby', 'rand' ); | |
} | |
if ( isset($_GET['sort']) && $_GET['sort'] == 'all' ) { | |
$query->set( 'posts_per_page', '-1' ); | |
} | |
} | |
} | |
add_action( 'pre_get_posts', 'ac_dynamic_sort_films' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment