Adding default custom fields on new posts in WordPress

Custom fields are essential part of every WordPress site. You know how to add it – Enter new – [type some name] – [type some content] – Add custom field. It’s not complicated process, but it is not as simple as it could be, especially if all of your posts need to have same custom fields, for example, price, size or some very general values. If it is your case, use this snippet and make your life easier.

<pre>add_action('wp_insert_post', 'mk_set_default_custom_fields');

function mk_set_default_custom_fields($post_id)
{
	if ( $_GET['post_type'] != 'page' ) {

		add_post_meta($post_id, 'price', '', true);
		add_post_meta($post_id, 'link', '', true);

	}

	return true;
}</pre>

Simple, right?

You can put numerous custom fields or put just one. It’s up to you.
Oh, I forgot. This adds an empty custom field (with no value). For adding custom field with some value add 

<pre>add_post_meta($post_id, 'custom field name', 'custom field value', true);</pre>

Your editors don’t like the dashboard? Redirect them!

Wordpress DashboardSince a small team (1dva) I freelanced for had migrated to WordPress, I’ve heard numerous times that old CMS was better. I know that our customers do not know why it is better, but I have to find out why they more like the Nano. The answer is more simple than I have expected – our customers don’t like the Dashboard, it is more friendly to go directly to Edit Posts page. Read how to redirect wordpress user from Dashboard. Continue reading