Last active
September 27, 2015 15:38
-
-
Save jeremyjaymes/1292896 to your computer and use it in GitHub Desktop.
WordPress: get category link by custom field.
This file contains hidden or 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 category link by custom field. | |
* Uses custom field that matches category slug. | |
*/ | |
function mytheme_category_link() { | |
global $post; | |
$cat_slug = get_post_meta( $post->ID, 'catslug', true); | |
$catid = get_category_by_slug( $cat_slug ); | |
$id = $catid->term_id; | |
$category_link = get_category_link( $id ); | |
echo '<a class="view-more" href="' . $category_link . '">' . __( 'View More', 'mytheme' ) . '</a>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment