How to create custom post type with category and extra fields?

How to create custom post type with category and extra fields?

How to create custom post type with category and extra fields?

Here we will explain to you how to create a custom post type with a category and extra fields in WordPress. This tutorial will help for making the custom post type so you can generate your posts with categories and show them on the front page.

Step 1)

Below is the code where you can create a custom post type with a category.

<?php
add_action( 'init', 'create_slider' );
function create_slider() {
    register_post_type( 'slider',
        array(
            'labels' => array(
                'name' => 'Slider',
                'singular_name' => 'Slide',
                'add_new' => 'Add New',
                'add_new_item' => 'Add New Slide',
                'edit' => 'Edit',
                'edit_item' => 'Edit Slide',
                'new_item' => 'New Slide',
                'view' => 'View',
                'view_item' => 'View Slide',
                'search_items' => 'Search Slider',
                'not_found' => 'No Slider found',
                'not_found_in_trash' => 'No Slider found in Trash',
                'parent' => 'Parent Slide'
            ),
 
            'public' => true,
            'menu_position' => 15,
            'supports' => array( 'title', 'editor', 'thumbnail' ),
            //'taxonomies' => array( '' ),
            //'menu_icon' => plugins_url( 'images/image.png', __FILE__ ),
            'has_archive' => true
        )
    );
}

function slider_taxonomy() {  
	register_taxonomy(  
		'slider_category',  //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces). 
		'slider',        //post type name
		array(  
			'hierarchical' => true,  
			'label' => 'Slider category',  //Display name
			'query_var' => true,
			'rewrite' => array(
				'slug' => 'slider_cat', // This controls the base slug that will display before each term
				'with_front' => false // Don't display the category base before 
			)
		)  
	);  
}
add_action( 'init', 'slider_taxonomy');

function add_post_format_filter_to_slider_dropdown($query){
	if (function_exists('custom_post_type_filter_dropdown')) {	
		$cur_post_type = 'slider';
		custom_post_type_filter_dropdown($cur_post_type,'slider_category',$query);
	}
}
add_action('restrict_manage_posts','add_post_format_filter_to_slider_dropdown');

function add_post_format_filter_to_slider($query){
	if (function_exists('custom_post_type_filter')) {
		$cur_post_type = 'slider';
		custom_post_type_filter($cur_post_type,'slider_category',$query);
	}
}	
add_action('pre_get_posts','add_post_format_filter_to_slider');
	
function slider_type_columns( $taxonomies ) {
	$taxonomies[] = 'slider_category';
	return $taxonomies;
}
add_filter( 'manage_taxonomies_for_slider_columns', 'slider_type_columns' );
		
	
add_action('init','add_custom_meta_boxes');
function add_custom_meta_boxes(){
	add_action( 'add_meta_boxes', 'slide_heading_meta_box_add' );
	add_action( 'save_post', 'slide_heading_meta_box_save' );
}
function slide_heading_meta_box_add()
{
    add_meta_box( 'slide_heading', 'Custom URL/Heading', 'slide_heading_meta_box', 'slider', 'normal', 'high' );
}
function slide_heading_meta_box()
{
	$custom_metas = get_post_custom( $post->ID );	
	$slide_url = isset( $custom_metas['slide_url'] ) ? esc_attr( $custom_metas['slide_url'][0] ) : '';
	$slide_heading = isset( $custom_metas['slide_heading'] ) ? esc_attr( $custom_metas['slide_heading'][0] ) : '';
	$heading_color = isset( $custom_metas['heading_color'] ) ? esc_attr( $custom_metas['heading_color'][0] ) : ''; ?>		
	<p>
		<label for="fom_link3">URL: </label>
		<input type="text" name="slide_url" id="slide_url" value="<?php echo $slide_url; ?>" size="34" />
		
		<label for="fom_link3">Heading: </label>
		<input type="text" name="slide_heading" id="slide_heading" value="<?php echo $slide_heading; ?>" size="34" maxlength="50" />
	
		<label for="fom_link3">Color: </label>
		<input type="text" name="heading_color" id="heading_color" value="<?php echo $heading_color; ?>" size="5" maxlength="10" />
	</p><?php
}

function slide_heading_meta_box_save($post_id){

	// Bail if we're doing an auto save
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
 
     // if our current user can't edit this post, bail
    if( !current_user_can( 'edit_post' ) ) return;
     
    // now we can actually save the data
    $allowed = array();
	
    // Make sure your data is set before trying to save it	
	if( isset( $_POST['slide_url'] ) ) {
		update_post_meta( $post_id, 'slide_url', $_POST['slide_url'] );
	}
	
	if( isset( $_POST['slide_heading'] ) ) {
		update_post_meta( $post_id, 'slide_heading', $_POST['slide_heading'] );
	}
	
	if( isset( $_POST['heading_color'] ) ) {
        update_post_meta( $post_id, 'heading_color', wp_kses( $_POST['heading_color'], $allowed ) );
	}
}

Step 2)

Now visit the admin side, and you can see your custom post type with the category and extra fields there.

7 responses

7 thoughts on “How to create custom post type with category and extra fields?”

  1. finasteride

    Hi, I do believe this is a great web site. I stumbledupon it 😉 I’m going to revisit once again since i have bookmarked it. Money and freedom is the greatest way to change, may you be rich and continue to guide others.

  2. craybet_znon

    I’ve been messing around on Craybet for about a couple months and wanted to share some thoughts because there’s not much discussion about it around here. I signed up randomly one night and registration literally took two minutes. Minimum deposit is $10 and that’s about what you’d expect. They threw in a sign-up bonus — matched my first deposit 100% up to 500 and 50 free spins on Gates of Olympus. Playthrough requirements were 35 times the bonus which isn’t amazing but not the worst I’ve seen.

    The game library is honestly pretty solid. You’ll find titles from Pragmatic Play, Evolution, and Microgaming — so like Gates of Olympus, Starburst, the usual heavy hitters. Probably close to 1500-2000 slots total if you count everything. The live dealer section is powered by Evolution which is legit — tried blackjack and Crazy Time with real dealers and had no complaints.

    Now the one thing that kinda bugged me was withdrawal times. Tried cashing out with Bitcoin and waited almost two days the first time. After that though things sped up. You can use credit cards, e-wallets like Skrill and Neteller, and BTC which is most bases. I’d check out what they’ve got going on at CrayBet to see for yourself.

    Mobile experience on Craybet on mobile is actually smooth. There’s no app to download though the browser version is responsive and all the games load fine. I played Book of Dead on my commute and didn’t notice any performance issues.

    Support at Craybet has been decent — they have live chat that gets you a person pretty quick usually. Reached out once about a bonus that didn’t credit and it was resolved pretty quickly. Not sure about operating under a Curacao license and that’s what most offshore casinos. Not everything is amazing — promo codes seem rare — but for what it is it does the job for me.

  3. craybet_kcon

    Been playing on Craybet for roughly six weeks or so and figured I’d share my experience because there’s not much discussion about it around here. Signed up on a whim and signing up was like 90 seconds. Min deposit was ten bucks which is about what you’d expect. I grabbed a welcome bonus — 100 percent match to $500 and fifty free spins on Sweet Bonanza. Rollover is 35 times the bonus which could be lower but it’s manageable.

    The game library is decent honestly. There’s games from Pragmatic Play, Betsoft, plus Play’n GO — meaning Book of Dead, Gonzo’s Quest, the usual heavy hitters. Somewhere around 2000 games when you add it all up. The live dealer section runs on Evolution which is smooth — tried roulette and Lightning Roulette with real dealers and it worked great.

    Now the one thing that annoyed me a little was withdrawal times. Tried cashing out with Visa and it took about 48 hours the first time. After that though things sped up. Payment options include Visa, Mastercard, e-wallets like Skrill and Neteller, and crypto which covers most bases. You can look at their current offers on svnewtech to see for yourself.

    Using Craybet on mobile is actually smooth. No dedicated app but the mobile site runs well and all the games load without issues. Played Book of Dead in bed and didn’t notice any lag or glitches.

    Support at Craybet is alright — live chat that gets you a person pretty quick usually. I contacted them about my verification docs and they sorted it same day. Licensing is Curacao-based from what I can tell and that’s what most platforms like this. Wouldn’t say it’s perfect — wish they had more payment options — but for what it is I keep coming back.

Leave a Reply

Your email address will not be published. Required fields are marked *