| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- // Dodaj akcję, aby zarejestrować niestandardowy typ postu
- add_action('init', 'register_custom_post_type');
- function register_custom_post_type() {
- $labels = array(
- 'name' => 'Emaile',
- 'singular_name' => 'Email',
- 'menu_name' => 'Emaile',
- 'name_admin_bar' => 'Emaile',
- 'add_new' => 'Dodaj nowy',
- 'add_new_item' => 'Dodaj nowy email',
- 'new_item' => 'Nowy email',
- 'edit_item' => 'Edytuj email',
- 'view_item' => 'Zobacz email',
- 'all_items' => 'Wszystkie emaile',
- 'search_items' => 'Szukaj emaili',
- 'not_found' => 'Nie znaleziono emaili',
- 'not_found_in_trash' => 'Nie znaleziono emaili w koszu',
- );
- $args = array(
- 'labels' => $labels,
- 'public' => false,
- 'publicly_queryable' => false,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'query_var' => true,
- 'rewrite' => array('slug' => 'emails'),
- 'capability_type' => 'post',
- 'has_archive' => true,
- 'hierarchical' => false,
- 'menu_position' => null,
- 'supports' => array('title', 'editor'),
- );
- register_post_type('email', $args);
- // Dodaj akcję, aby zarejestrować niestandardowe pola meta
- add_action('add_meta_boxes', 'add_email_meta_box');
- }
- function add_email_meta_box() {
- add_meta_box(
- 'email_meta_box',
- 'Adres E-mail',
- 'render_email_meta_box',
- 'project', // Tutaj używamy identyfikatora niestandardowego typu postu
- 'normal',
- 'default'
- );
- }
- function render_email_meta_box($post) {
- // Pobierz aktualną wartość pola meta
- $email_value = get_post_meta($post->ID, '_project_email', true);
- // Wyświetl pole input
- echo '<label for="project_email">Adres E-mail:</label>';
- echo '<input type="email" id="project_email" name="project_email" value="' . esc_attr($email_value) . '" />';
- }
- // Dodaj akcję, aby zapisać wartość pola meta
- add_action('save_post', 'save_email_meta');
- function save_email_meta($post_id) {
- if (isset($_POST['project_email'])) {
- update_post_meta($post_id, '_project_email', sanitize_email($_POST['project_email']));
- }
- }
|