Skip to content

Instantly share code, notes, and snippets.

@danieljwonder
Created September 25, 2018 02:46
Show Gist options
  • Select an option

  • Save danieljwonder/621a9be5d253f004d47dc24c6c1dfbb1 to your computer and use it in GitHub Desktop.

Select an option

Save danieljwonder/621a9be5d253f004d47dc24c6c1dfbb1 to your computer and use it in GitHub Desktop.
Add Portfolio Headlines to WordPress Categories
<?php
/* Add Portfolio Headlines to WordPress Categories */
function addPortfolioHeadlineFieldsToCat(){
$portfolio_headline = get_term_meta($_GET['tag_ID'], '_portfolio_headline', true);
$portfolio_sub_headline = get_term_meta($_GET['tag_ID'], '_portfolio_sub_headline', true);
?>
<h2><?php _e('Portfolio Headline Settings'); ?></h2>
<table class="form-table">
<tbody>
<tr class="form-field">
<th scope="row" valign="top"><label for="portfolio_headline"><?php _e('Portfolio Headline'); ?></label></th>
<td>
<input type="text" name="portfolio_headline" id="portfolio_headline" value="<?php echo $portfolio_headline ?>"><br />
<span class="description"><?php _e('Headline to appear over first image in category. '); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="portfolio_sub_headline"><?php _e('Portfolio Sub-Headline'); ?></label></th>
<td>
<input type="text" name="portfolio_sub_headline" id="portfolio_sub_headline" value="<?php echo $portfolio_sub_headline ?>"><br />
<span class="description"><?php _e('Sub-Headline to appear over first image in category. '); ?></span>
</td>
</tr>
</tbody>
</table>
<?php
}
add_action ( 'edit_category_form_fields', 'addPortfolioHeadlineFieldsToCat');
function saveCategoryFields() {
if ( isset( $_POST['portfolio_headline'] ) ) {
update_term_meta($_POST['tag_ID'], '_portfolio_headline', $_POST['portfolio_headline']);
}
if ( isset( $_POST['portfolio_headline'] ) ) {
update_term_meta($_POST['tag_ID'], '_portfolio_sub_headline', $_POST['portfolio_sub_headline']);
}
}
add_action ( 'edited_category', 'saveCategoryFields');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment