Custom texonomy with custom Post type

Add This Code in functions.php file.

/************/
/* Adding custom post type – Github Repository
/************/
function github_repository_custom_init() {
	$labels = array(
		'name' => 'Github Repository',
		'singular_name' => 'github_repository',
		'add_new' => 'Add New',
		'add_new_item' => 'Add New Repository',
		'edit_item' => 'Edit Repository',
		'new_item' => 'New Repository',
		'all_items' => 'All Repository',
		'view_item' => 'View Repository',
		'search_items' => 'Search Repository',
		'not_found' => 'No plans found',
		'not_found_in_trash' => 'No plans found in Trash',
		'parent_item_colon' => '',
		'menu_name' => 'Github Repository'
	);
	$args = array(
		'labels' => $labels,
		'public' => true,
		'publicly_queryable' => true,
		'show_ui' => true,
		'show_in_menu' => true,
		'query_var' => true,
		'rewrite' => array( 'slug' => 'github_repository' ),
		'capability_type' => 'post',
		'has_archive' => true,
		'hierarchical' => false,
		'menu_position' => null,
		'supports' => array( 'title', 'editor', 'thumbnail' ),
		'taxonomies' => array('category')
	);

	register_post_type( 'github_repository', $args );
}
add_action( 'init', 'github_repository_custom_init' );
/************/
/* Featch data Foreach loop 
/************/

$repository_value =0;
	$args = array(
		'post_type'=> 'repository' ,
		'category_name' => get_post_meta( get_the_ID(), 'keyword' ,true)
	);
	$repositorys = get_posts($args);

	foreach($repositorys as $repository)
	{
	$ID = $repository->ID;
	$repository_value++;
	$feat_image = wp_get_attachment_url( get_post_thumbnail_id($ID) );
	
	?>
	<a title="<?php echo get_the_title($ID); ?>" data-source="" href="<?php echo $feat_image; ?>"><img src="<?php echo $feat_image; ?>">
	</a>
<?php } 

/************/
/* Featch data while loop
/************/
$args = array( 
	'posts_per_page'   => 10,
	'orderby'          => 'post_date',
	'order'            => 'DESC',
	'post_type'        => 'repository',
	'post_status'      => 'publish',
	'category_name'    => 'my-category-slug'
);
$single_post = new WP_Query( $args );

while ( $single_post->have_posts() ) {
	$single_post->the_post();
	$feature_img_url = wp_get_attachment_url(get_post_thumbnail_id(get_the_id())); ?>
    
    <h2><?php echo get_the_title(); ?></h2>    
<?php }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s