I'm using wordpress codestar options framework to build a wordpress theme, for that i need to do following list of things:
add featured image support to the theme
add a custom post type called "institutions", add metabox options for that post type with the following list: text type, the title is features; select type, the title is regions with two options; gallery type, the title is gallery, repeater type, the title is bulletpoints; text type, the title is montly price; text type, the title is address; text type, the title is type;
please write style.css sample theme declaration comment
please generate the code for me, thanks.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Certainly! Here's how you can refactor the code to include the new custom taxonomy and metabox for the "institutions" post type:
php
// Add the 'category' taxonomy for 'institutions'
add_action('register_taxonomy', 'codestar_options_institution_taxonomy', 10, 3);
function codestar_options_institution_taxonomy($taxonomy, $label, $singular, $plural) {
// Register 'category' taxonomy for 'institutions'
$args = array(
'label' => $label,
'singular_label' => $singular,
'public' => true,
'rewrite' => array('slug' => 'category'),
'show_in_rest' => true,
);
register_taxonomy('category', 'institutions', $args);
}
// Add a metabox for 'category' taxonomy
add_action('add_meta_boxes', 'codestar_options_institution_category_metabox');
function codestar_options_institution_category_metabox() {
add_meta_box('codestar_category_meta_box', 'Category', 'codestar_options_institution_category_callback', 'institutions', 'normal', 'high');
}
function codestar_options_institution_category_callback($post) {
// Use nonce for verification
wp_nonce_field('codestar_options_institution_category_nonce', 'codestar_options_institution_category_nonce_field');
// Get the current category
$category = get_the_terms($post->ID, 'category');
$selected_category = isset($category[0]->slug) ? $category[0]->slug : '';
// Display the select field
echo '<label for="codestar_category_field">' . __('Category', 'codestar-options') . '</label>';
echo '<select name="codestar_category_field" id="codestar_category_field">';
$categories = get_categories(array('taxonomy' => 'category'));
foreach ($categories as $category) {
$selected = $category->slug === $selected_category ? ' selected' : '';
echo '<option value="' . $category->slug . '"' . $selected . '>' . $category->name . '</option>';
}
echo '</select>';
}
// Save the category value
add_action('save_post', 'codestar_options_institution_category_save', 10, 2);
function codestar_options_institution_category_save($post_id, $post) {
// Check for autosave, nonce, or user permissions
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || !isset($_POST['codestar_options_institution_category_nonce_field']) ||
!wp_verify_nonce($_POST['codestar_options_institution_category_nonce_field'], 'codestar_options_institution_category_nonce') ||
!current_user_can('edit_post', $post_id) ||
!get_post_meta($post_id, 'codestar_category_field', true)) {
return;
}
// Save the category value
update_post_meta($post_id, 'codestar_category_field', sanitize_text_field($_POST['codestar_category_field']));
}
For the style.css, you can add the following theme declaration:
css
/*
Theme Name: Your Theme Name
Theme URI: http://example.com/your-theme-uri/
Description: A custom theme for WordPress using the Codestar Options Framework.
Author: Your Name
Author URI: http://example.com
Version: 1.0
Text Domain: your-theme-text-domain
*/
Replace the placeholders with your actual theme information. This code adds a new custom taxonomy 'category' for the 'institutions' post type and a metabox to select a category. It also includes the necessary actions to save the selected category when the post is saved.