wp get custom post type category code example
Example 1: wp_query get custom post type
<?php
$args = array(
'post_type' => 'custom_type',
'post_status' => 'publish',
'posts_per_page' => 8,
'orderby' => 'title',
'order' => 'ASC',
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
print the_title();
the_excerpt();
endwhile;
wp_reset_postdata();
?>
Example 2: wp+create custom post type and category
add_action( 'init', 'create_news' );
function create_news ()
{
register_post_type( 'ecommerces',
array(
'labels' => array(
'name' => __( 'Ecommerces' ),
'singular_name' => __( 'Ecommerce' )
),
'public' => true,
'supports' => array ('title', 'editor', 'thumbnail')
)
);
register_taxonomy(
'ecommerce_cat',
'ecommerces',
array(
'labels' => array(
'name' => 'Ecommerce Categories',
'add_new_item' => 'Add New Ecommerce Category',
'new_item_name' => "New Ecommerce Category"
),
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'hasArchive' => true
)
);
}
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 100, 100, true );
}
?>