Created
March 8, 2017 12:56
-
-
Save hirejordansmith/2dbc9074cb414f7636d2d06a1763011e to your computer and use it in GitHub Desktop.
How to order get_terms() based on a custom field
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 | |
// Get terms - replace "SERMON" with your term | |
$terms = get_terms('SERMON'); | |
// Set an empty array | |
$sermon_series = array(); | |
// Loop through terms and build our array | |
foreach ( $terms as $term ) { | |
// Advanced Custom Fields Date field | |
$sermon_series_date = get_field( 'sermon_series_date', $term ); | |
$sermon_series[$sermon_series_date] = $term; | |
} | |
// Sort the terms by date | |
krsort( $sermon_series, SORT_NUMERIC ); | |
// This will build the terms as cards | |
// I also has a custom field being used for category image | |
foreach ( $sermon_series as $sermon_series_date => $term ) { | |
$term_id = $term->term_id; | |
$image_id = get_field('sermon_category_image', $term); | |
$image = wp_get_attachment_image($image_id, 'sermon-card'); | |
$intro_text = $term->meta[intro_text]; | |
$term_link = get_term_link( $term ); | |
?> | |
<div class="card"> | |
<a href="<?php echo $term_link; ?>"><?php echo $image ?></a> | |
<div class="card-content"> | |
<div class="title-wrap"> | |
<h3><a href="<?php echo $term_link; ?>"><?php echo $term->name; ?></a></h3> | |
</div> | |
<p><?php echo $intro_text ?></p> | |
<a class="read-more" href="<?php echo $term_link; ?>">View Sermons</a> | |
</div> | |
</div> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment