Home / Admin / Register Podcast Meta Fields
Duplicate Snippet

Embed Snippet on Your Site

Register Podcast Meta Fields

Automatically adds the 'Key Concepts', 'Referenced in this Episode', and 'Companion Post Link' input fields to the cb-episode editing screen to support LLM extraction and scholarly citations."

Craig Carroll
<10
Code Preview
php
<?php
<?php
/**
 * Add this as a new PHP snippet in WPCode to automatically build in the 
 * three new podcast meta fields (Key Concepts, References, Companion Link)
 * to the cb-episode post editing screen.
 */
add_action('add_meta_boxes', 'cb_register_podcast_meta_boxes');
function cb_register_podcast_meta_boxes() {
    add_meta_box(
        'cb_podcast_advanced_meta',
        'Podcast Episode: Advanced Details (LLM & Citations)',
        'cb_render_podcast_meta_boxes',
        'cb-episode',
        'normal',
        'high'
    );
}
function cb_render_podcast_meta_boxes($post) {
    // Add nonce for security
    wp_nonce_field('cb_podcast_meta_nonce_action', 'cb_podcast_meta_nonce');
    // Retrieve existing values
    $key_concepts = get_post_meta($post->ID, 'key_concepts', true);
    $references = get_post_meta($post->ID, 'referenced_in_episode', true);
    $companion = get_post_meta($post->ID, 'companion_post_url', true);
    
    echo '<style>
        .cb-meta-row { margin-bottom: 20px; }
        .cb-meta-row label { display: block; font-weight: bold; margin-bottom: 5px; }
        .cb-meta-row .description { color: #666; font-size: 12px; margin-bottom: 5px; display: block; }
        .cb-meta-row textarea { width: 100%; font-family: monospace; }
        .cb-meta-row input[type="url"] { width: 100%; }
    </style>';
    // Key Concepts
    echo '<div class="cb-meta-row">';
    echo '<label for="key_concepts">6. Key Concepts Defined</label>';
    echo '<span class="description">Format: "Concept — Definition" (one per line). Example: <em>Strategic silence — Deliberate non-response as an institutional posture.</em></span>';
    echo '<textarea id="key_concepts" name="key_concepts" rows="5">' . esc_textarea($key_concepts) . '</textarea>';
    echo '</div>';
    // References
    echo '<div class="cb-meta-row">';
    echo '<label for="referenced_in_episode">7. Referenced in this Episode (Citations)</label>';
    echo '<span class="description">The scholarly-citation-graph layer. Paste an HTML bulleted list or just text (it will be formatted automatically).</span>';
    echo '<textarea id="referenced_in_episode" name="referenced_in_episode" rows="5">' . esc_textarea($references) . '</textarea>';
    echo '</div>';
    // Companion URL
    echo '<div class="cb-meta-row">';
    echo '<label for="companion_post_url">8. Companion Post Link</label>';
    echo '<span class="description">Link to the response brief or written companion post.</span>';
    echo '<input type="url" id="companion_post_url" name="companion_post_url" value="' . esc_attr($companion) . '" placeholder="https://..." />';
    echo '</div>';
}
add_action('save_post', 'cb_save_podcast_meta_boxes');
function cb_save_podcast_meta_boxes($post_id) {
    // Security check
    if (!isset($_POST['cb_podcast_meta_nonce']) || !wp_verify_nonce($_POST['cb_podcast_meta_nonce'], 'cb_podcast_meta_nonce_action')) {
        return;
    }
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
    if (!current_user_can('edit_post', $post_id)) return;
    // Save Key Concepts
    if (isset($_POST['key_concepts'])) {
        update_post_meta($post_id, 'key_concepts', sanitize_textarea_field($_POST['key_concepts']));
    }
    // Save References (allowing basic HTML for lists)
    if (isset($_POST['referenced_in_episode'])) {
        update_post_meta($post_id, 'referenced_in_episode', wp_kses_post($_POST['referenced_in_episode']));
    }
    // Save Companion URL
    if (isset($_POST['companion_post_url'])) {
        update_post_meta($post_id, 'companion_post_url', sanitize_url($_POST['companion_post_url']));
    }
}
?>

Comments

Add a Comment