<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Michael Fields &#187; Custom Post Types</title>
	<atom:link href="http://wordpress.mfields.org/topics/custom-content-type/feed/" rel="self" type="application/rss+xml" />
	<link>http://wordpress.mfields.org</link>
	<description>I&#039;m a Theme Wrangler at Automattic! Rock!</description>
	<lastBuildDate>Tue, 27 Mar 2012 20:37:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Saving custom fields in quick or bulk edit mode in WordPress</title>
		<link>http://wordpress.mfields.org/bookmark/saving-custom-fields-in-quick-or-bulk-edit-mode-in-wordpress/</link>
		<comments>http://wordpress.mfields.org/bookmark/saving-custom-fields-in-quick-or-bulk-edit-mode-in-wordpress/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 14:11:21 +0000</pubDate>
		<dc:creator>Michael Fields</dc:creator>
		
		<guid isPermaLink="false">http://wordpress.mfields.org/?post_type=mfields_bookmark&#038;p=500</guid>
		<description><![CDATA[Visit Site]]></description>
			<content:encoded><![CDATA[Visit Site]]></content:encoded>
			<wfw:commentRss>http://wordpress.mfields.org/bookmark/saving-custom-fields-in-quick-or-bulk-edit-mode-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bookmark This!</title>
		<link>http://wordpress.mfields.org/2010/bookmark-this/</link>
		<comments>http://wordpress.mfields.org/2010/bookmark-this/#comments</comments>
		<pubDate>Tue, 14 Dec 2010 14:29:53 +0000</pubDate>
		<dc:creator>Michael Fields</dc:creator>
				<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://wordpress.mfields.org/?p=337</guid>
		<description><![CDATA[Earlier today I posted that I was thinking about creating a Chrome extension which would allow me to easily add new sites to my bookmarks section. My friend Devin responded asking if I knew about the Press This functionality. Although I was in fact aware of Press This, I had to admit that I&#8217;ve never]]></description>
			<content:encoded><![CDATA[<p>Earlier today <a href="http://twitter.com/#!/_mfields/status/14496398959452160">I posted</a> that I was thinking about creating a Chrome extension which would allow me to easily add new sites to my <a href="http://wordpress.mfields.org/bookmarks/">bookmarks section</a>. My friend <a href="http://wptheming.com/">Devin</a> responded asking if I knew about the <a href="http://codex.wordpress.org/Press_This">Press This</a> functionality. Although I was in fact <em>aware</em> of Press This, I had to admit that I&#8217;ve never actually used it before so I gave it a try. While I was quite impressed with what it did, it did not really do what I needed. <span id="more-337"></span></p>
<h2>How <em>Press This</em> Works</h2>
<p>If you log into WordPress and navigate to <em>Settings</em> -> <em>Writing</em> you will find a heading for &#8220;Press This&#8221; which instructs you to drag a link into the bookmarks bar in your browser. What you are bookmarking is not really a link but a small javascript application known as a <a href="http://en.wikipedia.org/wiki/Bookmarklet">bookmarklet</a>. You can now navigate to any webpage and when you click your <em>Press This</em> bookmarklet a popup window will open which displays a form allowing you to publish a post about the page. What impressed me here is that certain fields are already filled out:</p>
<ol>
<li>The title tag of the html document is inserted as the value of the post title.</li>
<li>If any text was selected, it is inserted into the content box</li>
<li>A link to the document is appended to the content box.</li>
</ol>
<h2>What I Need to Do</h2>
<ol>
<li>I need to create a bookmark and not a post.</li>
<li>I need to automatically set the title.</li>
<li>I need all custom taxonomies to display.</li>
<li>I need to set the name and value of a custom field.</li>
</ol>
<p>On my site I have one custom post_type registered (mfields_bookmark) which I use to archive interesting articles about web development that I have read. Unfortunately, Press This only seems to enable you to create &#8220;posts&#8221;. My initial idea was to create a custom popup window by copying the code from <code>press-this.php</code> into a custom function which would be triggered via <code>admin-ajax.php</code>. Seemed like a good idea, but it also sounded like a lot of work! After thinking about it, I really didn&#8217;t need the popup window, I would be happy if my bookmarklet just opened <code>post-new.php</code> in a new tab. So I started hacking <code>post-new.php's</code> query string to see if the post form would recognize any values&#8230; And it did!</p>
<h3>Post Title</h3>
<p>The post title can be injected by setting a value to <var>post_title</var>. Something Like this works rather well: <code>/wp-admin/post-new.php?post_title=TITLE</code></p>
<p>Although, I will not need to set the content here, I found that it can easily be set in much the same way: <code>/wp-admin/post-new.php?content=CONTENT</code></p>
<h3>Custom Field</h3>
<p>I only need one custom field to be defined for a <i>bookmark</i> post to function properly. I couldn&#8217;t find any hooks that I could use in core  so I decided to try a bit of javascript. I came up with the following code which I added to my theme&#8217;s functions.php file:</p>
<pre class="brush: php; title: ; notranslate">add_action( 'admin_head-post-new.php', 'mfields_process_bookmark_bookmarklet' );

function mfields_process_bookmark_bookmarklet() {
	global $post;
	if ( isset( $post-&gt;post_type ) &amp;&amp; 'mfields_bookmark' === $post-&gt;post_type &amp;&amp; isset( $_GET['mfields_bookmark_url'] ) ) {
		$url = esc_url( $_GET['mfields_bookmark_url'] );
		print &lt;&lt;&lt; EOF
		&lt;script type=&quot;text/javascript&quot;&gt;
		jQuery( document ).ready( function ( $ ) {
			$( '#metakeyselect' ).val( 'resource_url' );
			$( '#metavalue' ).text( '{$url}' );
		} );
		&lt;/script&gt;
EOF;
	}
}</pre>
<p>This function will fire during the <code>admin_head</code> action on <code>post-new.php</code> for the mfields_bookmark post_type. If <var>mfields_bookmark_url</var> is defined in the query string, the function will automatically select it as the name from the select box. Likewise, the value of <var>mfields_bookmark_url</var> will be used as the value of the custom field.</p>
<h2>Creating the Bookmarklet</h2>
<p>Now that WordPress has been configured to recognize this custom information, I needed to create an easy way of sending it. I copied the <i>Press This</i> javascript and reworked it to talk to <code>post-new.php</code>.</p>
<pre class="brush: jscript; title: ; notranslate">javascript:(
	function(){
		var title = encodeURIComponent( document.title ),
		bookmark = encodeURIComponent( document.location.href ),
		url = 'http://example.com/wp-admin/post-new.php?post_type=mfields_bookmark&amp;mfields_bookmark_url=' + bookmark + '&amp;post_title=' + title;
		window.open(url);
	}
)();</pre>
<p>Basically when you call this function, it will open post-new.php in a new tab sending the title and url of the document you were just viewing as well as setting the value of post_type to mfields_bookmark.</p>
<p>Adding this code to your browser is simple. In Chrome you can right-click the bookmarks toolbar and select <i>Add Page&#8230;</i>. Type &#8220;Bookmark This&#8221; as the name and use the javascript as the url. It might be a good idea to have the script on one line like this:</p>
<pre class="brush: jscript; title: ; notranslate">javascript:(function(){ var title = encodeURIComponent( document.title ), bookmark = encodeURIComponent( document.location.href ), url = 'http://example.com/wp-admin/post-new.php?post_type=mfields_bookmark&amp;mfields_bookmark_url=' + bookmark + '&amp;post_title=' + title; window.open(url); })();</pre>
<p>I hope that someone out there finds this useful. I&#8217;m pretty excited about it as it will really cut down the steps involved in posting bookmarks on my site.</p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.mfields.org/2010/bookmark-this/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Custom Content Type: Add Theme Redirect</title>
		<link>http://wordpress.mfields.org/2010/custom-content-type-add-theme-redirect/</link>
		<comments>http://wordpress.mfields.org/2010/custom-content-type-add-theme-redirect/#comments</comments>
		<pubDate>Fri, 14 May 2010 04:58:46 +0000</pubDate>
		<dc:creator>Michael Fields</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://wordpress.mfields.org/?p=190</guid>
		<description><![CDATA[The following piece of code will allow you to create a new page template that will be activated when a user visits http://example.com/custom-post-type/. It may be useful in creating an index page that lists all posts of a content type. The new page that it will recognize is dynamically created. The following should illustrate (please]]></description>
			<content:encoded><![CDATA[<p>The following piece of code will allow you to create a new page template that will be activated when a user visits <em>http://example.com/custom-post-type/</em>. It may be useful in creating an index page that lists all posts of a content type. The new page that it will recognize is dynamically created. <span id="more-190"></span></p>
<p>The following should illustrate (please change the bold text to reflect the post_name of your post type):</p>
<p>/wp-content/themes/my-active-theme/<b>my-content-type</b>-multiple.php</p>
<p>This code can be placed in your active theme&#8217;s functions.php file or added to a plugin.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
add_action( 'template_redirect', 'mfields_redirect_custom_content_multiple' );
function mfields_redirect_custom_content_multiple() {
	global $mfields_template;
	if( $mfields_template ) {
		include_once( $mfields_template );
		exit();
	}
	return false;
}

add_filter( 'status_header', 'mfields_template_404' );
function mfields_template_404( $c ) {
	global $mfields_template;
	$mfields_template = mfields_locate_custom_template();
	if( $mfields_template ) {
		$header = '200';
		$text = get_status_header_desc( $header );
		$protocol = $_SERVER[&quot;SERVER_PROTOCOL&quot;];
		if ( 'HTTP/1.1' != $protocol &amp;&amp; 'HTTP/1.0' != $protocol )
			$protocol = 'HTTP/1.0';

		return &quot;$protocol $header $text&quot;;
	}
	else
		return $c;
}

function mfields_locate_custom_template() {
	global $wp_post_types, $wp;
	if( is_404() ) {
		if( array_key_exists( $wp-&gt;request, $wp_post_types ) ) {
			$file = STYLESHEETPATH . '/' . $wp-&gt;request . '-multiple.php';
			$file = ( file_exists( $file ) ) ? $file : get_index_template();
			return $file;
		}
	}
	return false;
}
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.mfields.org/2010/custom-content-type-add-theme-redirect/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>

