Category Archives:
{
"name": "jqu
Re-Thinking The Na
A variety of conve
Q:
How to show th
Q:
How can I add
Bangladesh–Iran re
WASHINGTON — Repub
Q:
A question on
How to Add Google Q:
Use php to create a custom post type with different columns for title, date and content
I would like to create a custom post type which contains information about an event. I want the post title to go in the header of the post and not have a date (ex. 5th of June), I want to enter the date when I update the post. And I want to put the actual information in a textbox (ex. name, date, location) I haven't figured out yet how to do this. The code below creates the custom post type and allows me to select a year, month and day when I create the post, but when I go to edit the post I want to see these 3 boxes and not only title.
This is the code of the custom post type:
$labels = array(
'name' => _x( 'Eventos', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Eventos', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => _x( 'Eventos', 'admin menu', 'text_domain' ),
'all_items' => __( 'Eventos' ),
'view_item' => __( 'Ver Evento' ),
'add_new_item' => __( 'Adicionar Evento' ),
'add_new' => __( 'Adicionar Evento' ),
'edit_item' => __( 'Editar Evento' ),
'update_item' => __( 'Actualizar Evento' ),
'search_items' => __( 'Procurar Evento' ),
'not_found' => __( 'Evento não encontrado' ),
'not_found_in_trash' => __( 'Evento não encontrado em lixo' ),
'parent_item_colon' => __( 'Evento Pai:', 'text_domain' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'taxonomies' => array('post_tag'),
'supports' => array('title','editor','thumbnail'),
);
register_post_type( 'evento', $args );
}
This is the part of the code which allows me to choose the year, month and date:
$args = array(
'labels' => $labels,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','thumbnail'),
'rewrite' => array('slug' => 'eventos'),
);
register_post_type( 'eventos', $args );
And this is the code which creates the form to edit the post:
function evento_post_meta_box($object,$box) {
global $post;
$form_extra = array(
'class' => 'validate',
'label_attributes' => array('class' => 'col-lg-3 control-label'),
'input_attrs' => array('class' => 'form-control'),
);
switch($box) {
case 'Evento_info' :
$form_extra['title_field'] = array(
'label' => __( 'Título', 'text_domain' ),
'label_class' => 'col-lg-3 control-label'
);
$form_extra['evento_featured'] = array(
'label' => __( 'Título (Notas)', 'text_domain' ),
'label_class' => 'col-lg-3 control-label'
);
$evento_meta = get_post_meta( $post->ID, 'Evento_info', true );
$evento_featured = get_post_meta( $post->ID, 'Evento_featured', true );
$form_extra['content_field'] = array(
'label' => __( 'Evento', 'text_domain' ),
'label_class' => 'col-lg-3 control-label'
);
if($evento_meta) {
$form_extra['title_field']['placeholder'] = __( 'Escreva o título do Evento', 'text_domain' );
$form_extra['evento_featured']['placeholder'] = __( 'Escreva o título do Evento (Notas)', 'text_domain' );
$form_extra['content_field']['placeholder'] = __( 'Escreva o título do Evento', 'text_domain' );
}
break;
case 'Evento_date' :
$form_extra['meta_date_field'] = array(
'label' => __( 'Data de Envio', 'text_domain' ),
'label_class' => 'col-lg-3 control-label'
);
$form_extra['evento_featured'] = array(
'label' => __( 'Data de Envio (Notas)', 'text_domain' ),
'label_class' => 'col-lg-3 control-label'
);
if(isset($_GET['post_type']) && $_GET['post_type'] == 'evento') {
$evento_meta = get_post_meta( $post->ID, 'Evento_date', true );
$evento_featured = get_post_meta( $post->ID, 'Evento_featured', true );
}
$form_extra['form_field'] = array(
'label' => __( 'Data', 'text_domain' ),
'label_class' => 'col-lg-3 control-label'
);
if(isset($_GET['post_type']) && $_GET['post_type'] == 'evento') {
$form_extra['meta_date_field']['placeholder'] = __( 'Escreva a data do evento', 'text_domain' );
$form_extra['evento_featured']['placeholder'] = __( 'Escreva a data do evento (Notas)', 'text_domain' );
$form_extra['form_field']['placeholder'] = __( 'Escreva a data do evento', 'text_domain' );
}
break;
case 'Evento_location' :
$form_extra['meta_location_field'] = array(
'label' => __( 'Logradouro', 'text_domain' ),
'label_class' => 'col-lg-3 control-label'
);
$form_extra['evento_featured'] = array(
'label' => __( 'Logradouro (Notas)', 'text_domain' ),
'label_class' => 'col-lg-3 control-label'
);
$evento_meta = get_post_meta( $post->ID, 'Evento_location', true );
$evento_featured = get_post_meta( $post->ID, 'Evento_featured', true );
if($evento_meta) {
$form_extra['form_field'] = array(
'label' => __( 'Logradouro', 'text_domain' ),
'label_class' => 'col-lg-3 control-label'
);
$form_extra['meta_location_field']['placeholder'] = __( 'Escreva o logradouro', 'text_domain' );
}
break;
case 'Evento_logo' :
$form_extra['meta_image_field'] = array(
'label' => __( 'Logótipo', 'text_domain' ),
'label_class' => 'col-lg-3 control-label'
);
$form_extra['meta_location_field'] = array(
'label' => __( 'Logradouro', 'text_domain' ),
'label_class' => 'col-lg-3 control-label'
);
$evento_meta = get_post_meta( $post->ID, 'Evento_logo', true );
$evento_