Change ‘Enter Title Here’ Text for custom wordpress post

WordPress has functionality of create custom post type. By default wordpress shows “Enter Title Here” for every post type. Basically every content type is custom post in wordpress. When you create new post you will able to see this placeholder text.

For custom post type we need to add  Change ‘Enter Title Here’ Text for custom wordpress post. Many times we create custom post type for custom projects. Here in this article we shown you, how to create custom post type and change placeholder text.

When we want to customize custom post

If we are creating product custom type and want to add product description and their photos. For that you cannot use ‘Enter Title Here’ text. You need to give information to admin users with clear directions. So many times with custom post type you need to change placeholder text.

Using Following code You can create custom Post type

You need open functions.php file from your theme files and put following code.


add_action( 'init', 'create_product_init' );
/**
* Register a product post type.
*
* @link https://purabtech.in/create-wordpress-custom-post-type-permalink-structure/
*/
function create_product_init() {
$labels = array(
'name'               =>'Products',
'add_new_item'       => __( 'Add New product', 'your-plugin-textdomain' ),
'new_item'           => __( 'New product', 'your-plugin-textdomain' ),
'edit_item'          => __( 'Edit product', 'your-plugin-textdomain' ),
'view_item'          => __( 'View product', 'your-plugin-textdomain' )

);

$args = array(
'labels'             => $labels,
'public'             => true,
'publicly_queryable' => true,
'show_ui'            => true,
'show_in_menu'       => true,
'query_var'          => true,
'rewrite'            => array( 'slug' => 'product' ),
'capability_type'    => 'post',
'has_archive'        => true,
'hierarchical'       => false,
'menu_position'      => null,
'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);

register_post_type( 'product', $args );
}

 

Using above code you can create Product custom post.

Now Change ‘Enter Title Here’ Text for custom wordpress post

Use following code in functions.php file.


add_filter( 'enter_title_here', 'custom_product_enter_title' );

function custom_product_enter_title( $input ) {
global $post_type;

if ( is_admin() && $post_type == 'product')
return __( 'Enter Product Name here', 'your_textdomain' );

return $input;
}

 

Change ‘Enter Title Here’ Text for custom wordpress post
Change ‘Enter Title Here’ Text for custom wordpress post

 

Changed Placeholder text will look like as above shown in image. It is very simple and short code. You can change above code as per your project requirement.

For displaying custom post type on wordpress page you can check this article. If you want to upload file with meta box in wordpress with custom post type than check this article. There are many wordpress tutorial we written about wordpress custom post type.

 

how to check custom post type in wordpress

wordpress tutorial, how to check custom post type in wordpress. Many we want to execute some code on custom post type or want to execute code on post. Many we want to execute some code on custom post type or some times we want to execute code on normal pages or post.

how to check custom post type in wordpress

So here is solution. You just need to just add following code into your functions.php file which you can find in your wordpress theme folder.

function check_custom_post_type() {
global $wp_query;

$post_types = get_post_types(array('public'   => true,'_builtin' => false),'names','and');

foreach ($post_types  as $post_type ) {
if (get_post_type($post_type->ID) == get_post_type($wp_query->post->ID)) {
return true;
} else {
return false;
}
}
}

After this you can use following function in any wordpress file. For example you can use this method in single.php file.

if (check_custom_post_type()) {
//Current post is a custom post type
}
how to check custom post type in wordpress
wordpress tutorial, how to check custom post type in wordpress. Many we want to execute some code on custom post type or want to execute code on post.

How to save metadata in wordpress custom post type

Custom post type are very important in wordpress. Code for save metadata in wordpress custom post type. There are some plugins for creating the post type but I recommend custom code in function.php file.

How to save metadata in wordpress custom post type

I already written about custom post type. If you want to know about custom post type in detail then you can use following articles.

Here in this tutorial I showed How to save the meta data for your custom post type.

add_action( 'add_meta_boxes', 'job_detail_box' );

function job_detail_box() {
add_meta_box(
'job_detail_box',
__( 'job Detail', 'myplugin_textdomain' ),
'job_detail_box_content',
'job',
'normal',
'high'
);
}

function job_detail_box_content( $post ) {
// No need to globalise a post that is an argument on this callback
$meta_p = get_post_meta($post->ID, "jobs_price", true);
$meta_l = get_post_meta($post->ID, "jobs_location", true);

echo '<input type="hidden" name="jobs-nonce" id="jobs-nonce" value="' . wp_create_nonce( 'jobs-nonce' ) . '" />';

?>
<div>
<ul>

<ul>

<ul>
	<li><label>job Price</label>php echo $meta_p; ?>" /></li>
</ul>

</ul>

<ul>

<ul>
	<li><label>job Location</label>php echo $meta_l; ?>" /></li>
</ul>

</ul>

</ul>
</div>
<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
}

add_action ('save_post', 'save_jobs');

// The save_post hook provides the post id to the return function
function save_jobs( $post_id ){

if ( !wp_verify_nonce( $_POST['jobs-nonce'], 'jobs-nonce' )) {
return $post_id;
}

if ( !current_user_can( 'edit_post', $post_id ))
return $post_id;

update_post_meta($post_id, "jobs_price", $POST['jobs_price'] );
update_post_meta($post_id, "jobs_location", $POST['jobs_location'] );
}

How to save the meta data in wordpress custom post type
How to save the meta data in wordpress custom post type

	

In wordpress add tags and categories to custom post type

Many times we use the custom post type in wordpress. Wordpres tutorial, In wordpress add tags and categories to custom post type.  Some times we need to category and tags for custom post type which associated.

In wordpress add tags and categories to custom post type

you can use the following code in functions.php file.

// === CUSTOM POST TYPES === //
function create_my_post_types() {
	register_post_type( 'Services',
		array(
			'labels' => array(
				'name' => __( 'Services' ),
				'singular_name' => __( 'Services' ),
				'add_new_item' => 'Add New Services',
				'edit_item' => 'Edit Services',
				'new_item' => 'New Services',
				'search_items' => 'Search Services',
				'not_found' => 'No Services found',
				'not_found_in_trash' => 'No Services found in trash',
			),
			'_builtin' => false,
			'public' => true,
			'hierarchical' => false,
			'taxonomies' => array( 'website_type', 'service'),
			'supports' => array(
				'title',
				'editor',
				'excerpt',
                                'thumbnail'
			),
			'rewrite' => array( 'slug' => 'services', 'with_front' => false ),

		)
	);
}
add_action( 'init', 'create_my_post_types' );

// === CUSTOM TAXONOMIES === //
function my_custom_taxonomies() {
	register_taxonomy(
		'website_type',		// internal name = machine-readable taxonomy name
		'Services',		// object type = post, page, link, or custom post-type
		array(
			'hierarchical' => true,
			'label' => 'Website Types',	// the human-readable taxonomy name
			'query_var' => true,	// enable taxonomy-specific querying
			'rewrite' => array( 'slug' => 'website_type' ),	// pretty permalinks for your taxonomy?
		)
	);
	register_taxonomy(
		'service',
		'post',
		array(
			'hierarchical' => false,
			'label' => 'Service',
			'query_var' => true,
			'rewrite' => array( 'slug' => 'service' ),
		)
	);

}
add_action('init', 'my_custom_taxonomies', 0);

Please consult with your developer.

In wordpress add tags and categories to custom post type
In wordpress add tags and categories to custom post type

 

……………………..

solved wordpress custom post type pagination not working

From wordpress 3.0 version, wordpress started the custom post type functionality. There are API provided by wordpress for adding the pagination for custom post type. Some WP developers asked me about pagination of custom post type. That is very easy to add the pagination. Here in this article I given the code snippet for showing the pagination in custom post type.

solved wordpress custom post type pagination not working

For showing the custom post type we always use the query_post method.

Just use the following code in your template or theme file.

<?php get_header(); ?>

            <?php  query_posts( 'post_type=custom-post-type&paged='.$paged );
                                    if (have_posts()) : while (have_posts()) : the_post(); ?>

//loop here

              			<?php endwhile; ?>
				  <div id="nav-below" class="navigation">
					<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
					<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
				  </div><!-- #nav-below -->
				  <?php endif; wp_reset_query(); ?>

<?php get_footer(); ?>
solved wordpress custom post type pagination not working
solved wordpress custom post type pagination not working

Have fun!

create wordpress custom post type permalink structure

WordPress tutorial for, How to create wordpress custom post type permalink structure. Here we creating the Product post type with permalink.  we given code.

How to create wordpress custom post type permalink structure

Please open the functions.php file and put following code in that file.

/*
 * product custom post type added with new permalink
 */
function productposttype_with_custom_permalinks() {
register_post_type('product', array(
'label' => __('My product'),
 'singular_label' => __('product'),
 'show_ui' => true,
 'capability_type' => 'post',
 'hierarchical' => false,
 "supports" => array("title", "editor", "thumbnail", "author", "comments"),
 'taxonomies' => array('category', 'post_tag'), // this is IMPORTANT
'rewrite' => array('slug' => 'product'),
 'public' => true
    ));

//register_taxonomy( 'product-category', 'product', array ('hierarchical' => true, 'label' => __('product Categories'), 'rewrite' => array( 'slug' => 'product-category', 'with_front' => false ),));  // portfolio categories

add_rewrite_tag('%product%', '([^/]+)');
$extra_post_types = get_post_types(array('_builtin' => false, 'publicly_queryable' => true));
if (empty($extra_post_types))
return;
add_rewrite_tag('%post_type%', '(' . implode('|', $extra_post_types) . ')');
add_permastruct('product', '/%post_type%/%year%/%monthnum%/%day%/%product%/', true, 1);
}

/*
 * Funcation onload added the product custom post type
 */
add_action( 'init', 'productposttype_with_custom_permalinks' );

/*
 * product custom post added the permalink hook for enable the custom permalink
 * product custom post type
 */
function productposttype_with_product_permalink( $link, $post, $leavename, $sample ){
  if( 'product' != $post->post_type )
    return $link;
  $rewritecode = array(
    '%year%',
    '%monthnum%',
    '%day%',
    '%hour%',
    '%minute%',
    '%second%',
    $leavename? '' : '%postname%',
    '%post_id%',
    '%post_type%',
    $leavename? '' : '%pagename%',
    $leavename? '' : '%product%',
  );
  $unixtime = strtotime($post->post_date);
  $date = explode(' ', date('Y m d H i s', $unixtime));
  $replace_array = array(
    $date[0],
    $date[1],
    $date[2],
    $date[3],
    $date[4],
    $date[5],
    $post->post_name,
    $post->ID,
    $post->post_type,
    $post->post_name,
    $post->post_name,
  );
  $path = str_replace($rewritecode, $replace_array, $link);
  return $path;
}

add_action( 'post_type_link', 'productposttype_with_product_permalink', 10, 4 );

If you have any issues or problem with permalink then please write to me.

How to create wordpress custom post type permalink structure
How to create wordpress custom post type permalink structure

File upload with meta box in wordpress with custom post type

Code for File upload with meta box in wordpress using custom post type using meta boxes in wordpress. From wordpress 3.0 version wordpress introduced the custom_post_type function. Many people want to attach the file field with add_meta_box function. In this tutorial I will tell you how to upload file with custom meta box and post type. I tested above code with new wordpress versions 3.9. Still code is working fine.

Code for File upload with meta box in wordpress using custom post type using meta boxes in wordpress.

In this tutorial I will show you how to create the custom post type and add custom meta boxes to that post type and upload file with custom meta box.

After digging into wordpress files and functions I created following code. Just open your functions.php file and put following code in that file for creating custom post type.


<?php
 add_action('init', 'create_product');
 function create_product() {
 $product_args = array(
 'label' => __('Product'),
 'singular_label' => __('Product'),
 'public' => true,
 'show_ui' => true,
 'capability_type' => 'post',
 'hierarchical' => false,
 'rewrite' => true,
 'supports' => array('title', 'editor', 'thumbnail')
 );
 register_post_type('product',$product_args);
 }
?>

For uploading the file through custom meta box use the following code. Following code will add the file field to custom meta box and you are able to upload file or image to wordpress and upload file attachment to you custom post. Following code is very helpful to many wordpress theme and plugin developer. If you are having any issues or trouble using code then get back to me.

File upload with add_meta_box or custom_post_type in wordpress File upload with meta box in wordpress
File upload with add_meta_box or custom_post_type in wordpress File upload with meta box in wordpress

<?php

 add_action("admin_init", "add_product");
 add_action('save_post', 'update_purchase_url');
 function add_product(){
 add_meta_box("product_details", "product Options", "product_options", "product", "normal", "low");
 }
 function product_options(){
 global $post;
 $custom = get_post_custom($post->ID);
 $purchase_url = $custom["purchase_url"][0];
 $product_price = $custom["product_price"][0];
 $product_image = $custom["product_image"][0];
 $video_code = $custom["video_code"][0];

?>
 <div id="product-options">
 <label>Purchase URL:</label>php echo $purchase_url; ?>" />

 <label>Product Price:</label>php echo $product_price; ?>" />

 <label>Product Image:</label>php echo $product_image; ?>" />
 <img src="<?php echo $product_image; ?>">

 </div><!--end product-options-->
<?php
 }
 function update_purchase_url(){
 global $post;
 update_post_meta($post->ID, "purchase_url", $_POST["purchase_url"]);
 update_post_meta($post->ID, "product_price", $_POST["product_price"]);
 update_post_meta($post->ID, "product_image", $_POST["product_image"]);

 if(!empty($_FILES['product_image']['name'])){ //New upload
 require_once( ABSPATH . 'wp-admin/includes/file.php' );
 $override['action'] = 'editpost';

 $uploaded_file = wp_handle_upload($_FILES['product_image'], $override);

 $post_id = $post->ID;
 $attachment = array(
 'post_title' => $_FILES['product_image']['name'],
 'post_content' => '',
 'post_type' => 'attachment',
 'post_parent' => $post_id,
 'post_mime_type' => $_FILES['product_image']['type'],
 'guid' => $uploaded_file['url']
 );
 // Save the data
 $id = wp_insert_attachment( $attachment,$_FILES['product_image'][ 'file' ], $post_id );
 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $_FILES['product_image']['file'] ) );

update_post_meta($post->ID, "product_image", $uploaded_file['url']);
 }
 }
?>

For Uploading the file your post form need to add the enctype=”multipart/form-data” type to your form. Just use the following code in your functions.php file.

[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]


<?php
function fileupload_metabox_header(){
?>
<script type="text/javascript">
 jQuery(document).ready(function(){
 jQuery('form#post').attr('enctype','multipart/form-data');
 jQuery('form#post').attr('encoding','multipart/form-data');
 });
</script>
<?php }
add_action('admin_head', 'fileupload_metabox_header');

?>

[/viral-lock]

For checking all information in edit or preview section use following code.


<?php

add_action("manage_posts_custom_column",  "product_custom_columns");
add_filter("manage_edit-product_columns", "product_edit_columns");

function product_edit_columns($columns){
 $columns = array(
 "cb" => "<input type=\"checkbox\" />",
 "title" => "Product Title",
 "purchase_url" => "Purchase URL",
 "product_price" => "Product Price",
 "product_image" => "Product Image",
 );
 return $columns;
}
function product_custom_columns($column){
 global $post;
 switch ($column) {
 case "purchase_url":
 $custom = get_post_custom();
 echo $custom["purchase_url"][0];
 break;
 case "product_price":
 $custom = get_post_custom();
 echo $custom["product_price"][0];
 break;
 case "product_image":
 $custom = get_post_custom();
 $img_url =$custom["product_image"][0];
 echo "<image src=".$img_url." height=100 width=100 />";
 break;
 }
}

?>

File upload with meta box in wordpress
File upload with meta box in wordpress

Above code is useful for any type of customization. If you are having any issue with using this code then please get back to me.