my code stock.com

wordpress functions template with code to add nex post type, taxonomy and post meta. Jorge Simoes

Snippet options

Download: Download snippet as functionsphp.php.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

add_action( 'admin_init', 'jor_banners_admin_menu' );
function jor_banners_admin_menu(){
       if ( function_exists( 'add_meta_box' ) ) {
               add_meta_box( 'banners-post', 'Banner del Post', 'jor_banners_post', 'post', 'advanced');
			   add_meta_box( 'banners-post', 'Banner del Post', 'jor_banners_post', 'informes', 'side');
       }
}

function jor_banners_post(){
       global $post;
       if ( !($banner_ticket_url = get_post_meta($post->ID,'_banner_ticket_url',true)) )
                       $banner_ticket_url = "";
       ?>
<P>Indique el URL del banner que deba aparecer en la parte superior de las noticias (en caso de tener uno):</P>

		<p class="banner_ticket_url_box">
		       <label for="banner_ticket_url">
		               URL Banner (Ticket):
		       </label>
		       <br />
		       <input id="banner_ticket_url" type="text" name="banner_ticket_url" value="<?php echo $banner_ticket_url; ?>" style="width: 100%"/>
		</p>
       <?php
}

add_action( 'save_post', 'jor_post_published' );
add_action( 'publish_post', 'jor_post_published' );
function jor_post_published($post_id){
       $banner_ticket_url = (isset($_POST['banner_ticket_url']))?$_POST['banner_ticket_url']:'';
       add_post_meta($post_id, '_banner_ticket_url', $banner_ticket_url, true)
                       or update_post_meta($post_id, '_banner_ticket_url', $banner_ticket_url);
}

add_action( 'delete_post', 'jor_delete_post' );
function jor_delete_post($post_id){
       delete_post_meta($post_id, '_banner_ticket_url');
}








$labels = array(
       'name' => 'Informes',
       'singular_name' => 'Informe',
       'add_new' => 'Agregar Informe',
       'add_new_item' => 'Agregar nuevo informe',
       'edit_item' => 'Editar informe',
       'new_item' => 'Nuevo informe',
       'view_item' => 'Ver informe',
       'search_items' => 'Buscar informe',
       'not_found' => 'No se encontraron informes',
       'not_found_in_trash' => 'No hay informes en la papelera',
       'parent_item_colon' => ''
);
register_post_type('informes', array(
	'taxonomies' => array('tipo-publicacion', 'tag'),
   'label' => __('Informes'),
   'singular_label' => __('Informe'),
       'labels' => $labels,
   'public' => true,
   'show_ui' => true,
       'menu_position' => 6,
   'hierarchical' => false,
   'supports' => array('title', 'editor', 'excerpt', 'thumbnail')
));


/*
 new WP_Query(array(
	'showposts' => 3,
	'post_type' => 'publicacion',
'tipo-publicacion' => 'libros'))  
 */

 
 
 add_action( 'init', 'create_book_taxonomies', 0 );
function create_book_taxonomies()
{
 // Add new taxonomy, make it hierarchical (like categories)
 $labels = array(
   'name' => 'Tipos de Publicaciónes',
   'singular_name' => 'Tipo de Publicación',
   'search_items' =>  'Buscar',
   'all_items' => __( 'Todos' ),
   'parent_item' => __( 'Padres' ),
   'parent_item_colon' => __( 'Sub-tipo de Publicación:' ),
   'edit_item' => __( 'Editar' ),
   'update_item' => __( 'Actualizar' ),
   'add_new_item' => __( 'Agregar un Tipo de Publicación' ),
   'new_item_name' => __( 'Nuevo Tipo de Publicación' ),
   'menu_name' => __( 'Tipo de Publicación' )
 );
 register_taxonomy('tipo-publicacion', array('informes'), array(
   'hierarchical' => true,
   'labels' => $labels,
   'show_ui' => true,
   'query_var' => true,
   'rewrite' => array( 'slug' => 'tipo-publicacion' )
 ));
 register_taxonomy_for_object_type('category', 'informes');
}



register_taxonomy_for_object_type('category', 'informes');

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.