Skip to content

Instantly share code, notes, and snippets.

@JoaquinGA
Created April 18, 2017 16:10
Show Gist options
  • Save JoaquinGA/c31e01a92130f7a3947e014065c68f51 to your computer and use it in GitHub Desktop.
Save JoaquinGA/c31e01a92130f7a3947e014065c68f51 to your computer and use it in GitHub Desktop.
Crear custom post
<?php
if ( ! function_exists('Custom_Post_Type_Receta') ) {
// Register Custom Post Type
function Custom_Post_Type_Receta() {
$labels = array(
'name' => _x( 'Recetas', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Receta', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Recetas', 'text_domain' ),
'name_admin_bar' => __( 'Recetas', 'text_domain' ),
'archives' => __( 'Directorio de recetas', 'text_domain' ),
'parent_item_colon' => __( 'Receta Padre', 'text_domain' ),
'all_items' => __( 'Todas las recetas', 'text_domain' ),
'add_new_item' => __( 'Añadir receta', 'text_domain' ),
'add_new' => __( 'Añadir nueva', 'text_domain' ),
'new_item' => __( 'Nueva receta', 'text_domain' ),
'edit_item' => __( 'Editar receta', 'text_domain' ),
'update_item' => __( 'Actualizar receta', 'text_domain' ),
'view_item' => __( 'Ver receta', 'text_domain' ),
'search_items' => __( 'Buscar receta', 'text_domain' ),
'not_found' => __( 'No encontrada', 'text_domain' ),
'not_found_in_trash' => __( 'No encontrada en la papelera', 'text_domain' ),
'featured_image' => __( 'Imagen destacada', 'text_domain' ),
'set_featured_image' => __( 'Definir imagen destacada', 'text_domain' ),
'remove_featured_image' => __( 'Borrar imagen destacada', 'text_domain' ),
'use_featured_image' => __( 'Usar como imagen destacada', 'text_domain' ),
'insert_into_item' => __( 'Añadir a la receta', 'text_domain' ),
'uploaded_to_this_item' => __( 'Actualizado a la receta', 'text_domain' ),
'items_list' => __( 'Lista de recetas', 'text_domain' ),
'items_list_navigation' => __( 'Navegación en la lista de recetas', 'text_domain' ),
'filter_items_list' => __( 'Filtrar lista de recetas', 'text_domain' ),
);
$args = array(
'label' => __( 'Receta', 'text_domain' ),
'description' => __( 'Tipo de contenido receta', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'custom-fields', ),
'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'receta', $args );
}
add_action( 'init', 'Custom_Post_Type_Receta', 0 );
}
function crearReceta($nombre="receta", $mail="no definido", $toquemagico="no definido") {
// Create post object
$my_post = array(
'post_title' => $nombre,
'post_type' => 'receta',
'post_content' => '',
'post_status' => 'publish',
'post_author' => 1 // Obligamos a que el autor sea el súperadministrador
);
$new_post_id = wp_insert_post($my_post); // insertamos la entrada y obtenemos su id
update_post_meta($new_post_id, 'nombre', $nombre);
update_post_meta($new_post_id, 'mail', $mail);
update_post_meta($new_post_id, 'toquemagico', $toquemagico);
return($new_post_id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment