Custom Post Type Blocks and Locals Taxonomies
Insert blocks of code to many places
// Register Custom Post Type
function bloco_post_type() {
$labels = array(
'name' => _x( 'Blocos', 'Post Type General Name', 'theme' ),
'singular_name' => _x( 'Bloco', 'Post Type Singular Name', 'theme' ),
'menu_name' => __( 'Blocos', 'theme' ),
'name_admin_bar' => __( 'Blocos', 'theme' ),
'parent_item_colon' => __( 'Pai:', 'theme' ),
'all_items' => __( 'Todos', 'theme' ),
'add_new_item' => __( 'Adicionar novo', 'theme' ),
'add_new' => __( 'Adicionar', 'theme' ),
'new_item' => __( 'Novo', 'theme' ),
'edit_item' => __( 'Editar', 'theme' ),
'update_item' => __( 'Atualizar', 'theme' ),
'view_item' => __( 'Ver', 'theme' ),
'search_items' => __( 'Pesquisar', 'theme' ),
'not_found' => __( 'Nada encontrado', 'theme' ),
'not_found_in_trash' => __( 'Nada na lixeira', 'theme' ),
);
$args = array(
'label' => __( 'bloco', 'theme' ),
'description' => __( 'Blocos distribuidos em vários locais do site', 'theme' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields', ),
//'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-screenoptions',
'show_in_admin_bar' => false,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => true,
'rewrite' => true,
'capability_type' => 'page',
);
register_post_type( 'bloco', $args );
}
// Hook into the 'init' action
add_action( 'init', 'bloco_post_type', 0 );
// Register Custom Taxonomy
function local_taxonomy() {
$labels = array(
'name' => _x( 'Locais', 'Taxonomy General Name', 'theme' ),
'singular_name' => _x( 'Local', 'Taxonomy Singular Name', 'theme' ),
'menu_name' => __( 'Locais', 'theme' ),
'all_items' => __( 'Todos', 'theme' ),
'parent_item' => __( 'Pai', 'theme' ),
'parent_item_colon' => __( 'Pai:', 'theme' ),
'new_item_name' => __( 'Novo', 'theme' ),
'add_new_item' => __( 'Adicionar novo', 'theme' ),
'edit_item' => __( 'Editar', 'theme' ),
'update_item' => __( 'Atualizar', 'theme' ),
'view_item' => __( 'Ver', 'theme' ),
'separate_items_with_commas' => __( 'Separa por vírgulas', 'theme' ),
'add_or_remove_items' => __( 'Adicionar remover', 'theme' ),
'choose_from_most_used' => __( 'Escolha entre os mais usados', 'theme' ),
'popular_items' => __( 'Mais usados', 'theme' ),
'search_items' => __( 'Pesquisar', 'theme' ),
'not_found' => __( 'Nada encontrado', 'theme' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => false,
'show_in_nav_menus' => false,
'show_tagcloud' => true,
);
register_taxonomy( 'local', array( 'bloco' ), $args );
}
// Hook into the 'init' action
add_action( 'init', 'local_taxonomy', 0 );
/* HOW TO USE THIS
$args = array(
'post_type' => 'bloco',
'taxonomy' => 'local',
'term' => 'BLOCK-NAME',
'posts_per_page' => 4,
'orderby' => 'rand',
'order' => 'DESC'
);
query_posts($args);
while (have_posts()) : the_post();
//.. DO SOMETHING
endwhile;
wp_reset_query()
*/