<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Custom Post Type Permalinks &#8211; Part 2</title>
	<atom:link href="http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2/feed" rel="self" type="application/rss+xml" />
	<link>http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2</link>
	<description>Dynamic WordPress Theme</description>
	<lastBuildDate>Tue, 15 May 2012 17:59:42 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Ian</title>
		<link>http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2#comment-14037</link>
		<dc:creator>Ian</dc:creator>
		<pubDate>Tue, 08 May 2012 22:44:56 +0000</pubDate>
		<guid isPermaLink="false">http://shibashake.com/wordpress-theme/?p=6451#comment-14037</guid>
		<description>Thanks so much for this in depth post. Really saved me on a bad permalink custom post type I had set up.  I updated the permalink structure and they all broke. They are fixed now!</description>
		<content:encoded><![CDATA[<p>Thanks so much for this in depth post. Really saved me on a bad permalink custom post type I had set up.  I updated the permalink structure and they all broke. They are fixed now!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gam</title>
		<link>http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2#comment-13666</link>
		<dc:creator>Gam</dc:creator>
		<pubDate>Thu, 26 Apr 2012 01:06:38 +0000</pubDate>
		<guid isPermaLink="false">http://shibashake.com/wordpress-theme/?p=6451#comment-13666</guid>
		<description>There was a question about showing cats and sub-cats in the url, like you can with regular wordpress categories.  Of note here is when you register the taxonomy, there is a setting in the rewrite rules to do this.

Under rewrite, the argument pair &#039;hierarchical&#039; =&gt; true, turns on allowing /topic/sub-topic/super-sub-topic/, based on your structure, in the example called topic.

&lt;code&gt;
register_taxonomy(&#039;topic&#039;, &#039;gam_qa&#039;,
				array(
					&#039;labels&#039; =&gt; array(
						&#039;name&#039; =&gt; _x( &#039;Topics&#039;, &#039;taxonomy general name&#039; ),
						&#039;singular_name&#039; =&gt; _x( &#039;Topic&#039;, &#039;taxonomy singular name&#039; ),
						&#039;search_items&#039; =&gt;  __( &#039;Search Topics&#039; ),
						&#039;all_items&#039; =&gt; __( &#039;All Topics&#039; ),
						&#039;parent_item&#039; =&gt; __( &#039;Parent Topic&#039; ),
						&#039;parent_item_colon&#039; =&gt; __( &#039;Parent Topic:&#039; ),
						&#039;edit_item&#039; =&gt; __( &#039;Edit Topic&#039; ), 
						&#039;update_item&#039; =&gt; __( &#039;Update Topic&#039; ),
						&#039;add_new_item&#039; =&gt; __( &#039;Add New Topic&#039; ),
						&#039;new_item_name&#039; =&gt; __( &#039;New Topic Name&#039; ),
						&#039;menu_name&#039; =&gt; __( &#039;Topics&#039; ),
					),
					&#039;public&#039; =&gt; true,
					&#039;show_ui&#039; =&gt; true,
					&#039;hierarchical&#039; =&gt; true,
					&#039;query_var&#039; =&gt; true,
					&#039;rewrite&#039; =&gt; array( &#039;slug&#039; =&gt; &#039;q-and-a/topic&#039;, &#039;with_front&#039; =&gt; true, &#039;hierarchical&#039; =&gt; true ),
					&#039;capabilities&#039; =&gt; array(
						&#039;manage_terms&#039; =&gt; &#039;manage_qa_terms&#039;,
						&#039;edit_terms&#039; =&gt; &#039;edit_qa_terms&#039;,
						&#039;delete_terms&#039; =&gt; &#039;delete_qa_terms&#039;,
						&#039;assign_terms&#039; =&gt; &#039;assign_qa_terms&#039;
					)
				)
			);
&lt;/code&gt;

Then the function you call from.  This is a stripped down version, using only the %topic% tag, which will be the name of your custom taxonomy.

The code looks for a parent to the topic, and as long as it finds one, adds it to the url.

&lt;code&gt;
function gam_qa_permalinks($permalink, $post_id, $leavename) {
			
			$post = get_post($post_id);
			$rewrite_code = array(
				&#039;%topic%&#039;
			);
			
			if ( &#039;&#039; != $permalink &amp;&amp; !in_array($post-&gt;post_status, array(&#039;draft&#039;, &#039;pending&#039;, &#039;auto-draft&#039;)) ) {
				
				if ( strpos($permalink, &#039;%topic%&#039;) !== false ) {
					$terms = wp_get_object_terms($post-&gt;ID, &#039;topic&#039;);
					if (!is_wp_error($terms) &amp;&amp; !empty($terms) &amp;&amp; is_object($terms[0])) {
						$topics[] = $terms[0]-&gt;slug;
						
						$parent = $terms[0]-&gt;parent;
						while($parent) {
							$term = get_term($parent, &#039;topic&#039;);
							$parent = $term-&gt;parent;
							$topics[] = $term-&gt;slug;
						}
						$topics = array_reverse($topics);
						
						$taxonomy_slug = join(&#039;/&#039;, $topics);
					}else{
						$taxonomy_slug = &#039;no-topic&#039;;
					}
				}else{
					$taxonomy_slug = &#039;&#039;;
				}
				
				$rewrite_replace =
				array(
					$taxonomy_slug
				);
				$permalink = str_replace($rewrite_code, $rewrite_replace, $permalink);
			} else { // if they&#039;re not using the fancy permalink option
			}
			return $permalink;
		}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>There was a question about showing cats and sub-cats in the url, like you can with regular wordpress categories.  Of note here is when you register the taxonomy, there is a setting in the rewrite rules to do this.</p>
<p>Under rewrite, the argument pair &#8216;hierarchical&#8217; =&gt; true, turns on allowing /topic/sub-topic/super-sub-topic/, based on your structure, in the example called topic.</p>
<p><code><br />
register_taxonomy('topic', 'gam_qa',<br />
				array(<br />
					'labels' =&gt; array(<br />
						'name' =&gt; _x( 'Topics', 'taxonomy general name' ),<br />
						'singular_name' =&gt; _x( 'Topic', 'taxonomy singular name' ),<br />
						'search_items' =&gt;  __( 'Search Topics' ),<br />
						'all_items' =&gt; __( 'All Topics' ),<br />
						'parent_item' =&gt; __( 'Parent Topic' ),<br />
						'parent_item_colon' =&gt; __( 'Parent Topic:' ),<br />
						'edit_item' =&gt; __( 'Edit Topic' ),<br />
						'update_item' =&gt; __( 'Update Topic' ),<br />
						'add_new_item' =&gt; __( 'Add New Topic' ),<br />
						'new_item_name' =&gt; __( 'New Topic Name' ),<br />
						'menu_name' =&gt; __( 'Topics' ),<br />
					),<br />
					'public' =&gt; true,<br />
					'show_ui' =&gt; true,<br />
					'hierarchical' =&gt; true,<br />
					'query_var' =&gt; true,<br />
					'rewrite' =&gt; array( 'slug' =&gt; 'q-and-a/topic', 'with_front' =&gt; true, 'hierarchical' =&gt; true ),<br />
					'capabilities' =&gt; array(<br />
						'manage_terms' =&gt; 'manage_qa_terms',<br />
						'edit_terms' =&gt; 'edit_qa_terms',<br />
						'delete_terms' =&gt; 'delete_qa_terms',<br />
						'assign_terms' =&gt; 'assign_qa_terms'<br />
					)<br />
				)<br />
			);<br />
</code></p>
<p>Then the function you call from.  This is a stripped down version, using only the %topic% tag, which will be the name of your custom taxonomy.</p>
<p>The code looks for a parent to the topic, and as long as it finds one, adds it to the url.</p>
<p><code><br />
function gam_qa_permalinks($permalink, $post_id, $leavename) {</p>
<p>			$post = get_post($post_id);<br />
			$rewrite_code = array(<br />
				'%topic%'<br />
			);</p>
<p>			if ( '' != $permalink &amp;&amp; !in_array($post-&gt;post_status, array('draft', 'pending', 'auto-draft')) ) {</p>
<p>				if ( strpos($permalink, '%topic%') !== false ) {<br />
					$terms = wp_get_object_terms($post-&gt;ID, 'topic');<br />
					if (!is_wp_error($terms) &amp;&amp; !empty($terms) &amp;&amp; is_object($terms[0])) {<br />
						$topics[] = $terms[0]-&gt;slug;</p>
<p>						$parent = $terms[0]-&gt;parent;<br />
						while($parent) {<br />
							$term = get_term($parent, 'topic');<br />
							$parent = $term-&gt;parent;<br />
							$topics[] = $term-&gt;slug;<br />
						}<br />
						$topics = array_reverse($topics);</p>
<p>						$taxonomy_slug = join('/', $topics);<br />
					}else{<br />
						$taxonomy_slug = 'no-topic';<br />
					}<br />
				}else{<br />
					$taxonomy_slug = '';<br />
				}</p>
<p>				$rewrite_replace =<br />
				array(<br />
					$taxonomy_slug<br />
				);<br />
				$permalink = str_replace($rewrite_code, $rewrite_replace, $permalink);<br />
			} else { // if they're not using the fancy permalink option<br />
			}<br />
			return $permalink;<br />
		}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyle</title>
		<link>http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2#comment-13472</link>
		<dc:creator>Kyle</dc:creator>
		<pubDate>Wed, 18 Apr 2012 21:02:29 +0000</pubDate>
		<guid isPermaLink="false">http://shibashake.com/wordpress-theme/?p=6451#comment-13472</guid>
		<description>You just saved my sanity.  I&#039;ve been fighting with these dang ole permalinks/pagination issues for the last week straight.  

Great stuff, keep it up and thanks!</description>
		<content:encoded><![CDATA[<p>You just saved my sanity.  I&#8217;ve been fighting with these dang ole permalinks/pagination issues for the last week straight.  </p>
<p>Great stuff, keep it up and thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ShibaShake</title>
		<link>http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2#comment-12778</link>
		<dc:creator>ShibaShake</dc:creator>
		<pubDate>Wed, 28 Mar 2012 03:05:38 +0000</pubDate>
		<guid isPermaLink="false">http://shibashake.com/wordpress-theme/?p=6451#comment-12778</guid>
		<description>Try
&#039;/features/%year%/%monthnum%/%day%/%feature%&#039;</description>
		<content:encoded><![CDATA[<p>Try<br />
&#8216;/features/%year%/%monthnum%/%day%/%feature%&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amy</title>
		<link>http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2#comment-12760</link>
		<dc:creator>Amy</dc:creator>
		<pubDate>Tue, 27 Mar 2012 13:35:20 +0000</pubDate>
		<guid isPermaLink="false">http://shibashake.com/wordpress-theme/?p=6451#comment-12760</guid>
		<description>Very basic error, not sure if I&#039;m being silly. I&#039;ve put the &#039;// Add filter to plugin init function&#039; at the top of functions and then am using a custom post type called features, followed all your steps above.

I want my structure to be

features/%year%/%month/%day%/%postname%

but I&#039;m just getting a 404 error?

&lt;code&gt;add_action(&#039;init&#039;, &#039;feature_register&#039;);
 
function feature_register() {
 
	$labels = array(
		&#039;name&#039; =&gt; _x(&#039;Feature&#039;, &#039;post type general name&#039;),
		&#039;singular_name&#039; =&gt; _x(&#039;Feature&#039;, &#039;post type singular name&#039;),
		&#039;add_new&#039; =&gt; _x(&#039;Add New&#039;, &#039;Feature item&#039;),
		&#039;add_new_item&#039; =&gt; __(&#039;Add New Feature&#039;),
		&#039;edit_item&#039; =&gt; __(&#039;Edit Feature Item&#039;),
		&#039;new_item&#039; =&gt; __(&#039;New Feature Item&#039;),
		&#039;view_item&#039; =&gt; __(&#039;View Feature Item&#039;),
		&#039;search_items&#039; =&gt; __(&#039;Search Feature&#039;),
		&#039;not_found&#039; =&gt;  __(&#039;Nothing found&#039;),
		&#039;not_found_in_trash&#039; =&gt; __(&#039;Nothing found in Trash&#039;),
		&#039;parent_item_colon&#039; =&gt; &#039;&#039;
	);
 
	$args = array(
		&#039;labels&#039; =&gt; $labels,
		&#039;public&#039; =&gt; true,
		&#039;publicly_queryable&#039; =&gt; true,
		&#039;show_ui&#039; =&gt; true,
		&#039;query_var&#039; =&gt; true,
		&#039;rewrite&#039; =&gt; false,
		&#039;capability_type&#039; =&gt; &#039;post&#039;,
		&#039;hierarchical&#039; =&gt; false,
		&#039;has_archive&#039; =&gt; true,
		&#039;menu_position&#039; =&gt; null,
		&#039;supports&#039; =&gt; array(&#039;title&#039;,&#039;editor&#039;,&#039;thumbnail&#039;, &#039;comments&#039;,&#039;trackbacks&#039;, &#039;author&#039;),
		&#039;taxonomies&#039; =&gt; array(&#039;post_tag&#039;),
	  ); 
 
	register_post_type( &#039;feature&#039; , $args );
}



// add to our plugin init function
global $wp_rewrite;
$feature_structure = &#039;/features/%year%/%monthnum%/%day%/%postname%&#039;;
$wp_rewrite-&gt;add_rewrite_tag(&quot;%feature%&quot;, &#039;([^/]+)&#039;, &quot;feature=&quot;);
$wp_rewrite-&gt;add_permastruct(&#039;feature&#039;, $feature_structure, false);
&lt;/code&gt;

Any help appreciated, thanks</description>
		<content:encoded><![CDATA[<p>Very basic error, not sure if I&#8217;m being silly. I&#8217;ve put the &#8216;// Add filter to plugin init function&#8217; at the top of functions and then am using a custom post type called features, followed all your steps above.</p>
<p>I want my structure to be</p>
<p>features/%year%/%month/%day%/%postname%</p>
<p>but I&#8217;m just getting a 404 error?</p>
<p><code>add_action('init', 'feature_register');</p>
<p>function feature_register() {</p>
<p>	$labels = array(<br />
		'name' =&gt; _x('Feature', 'post type general name'),<br />
		'singular_name' =&gt; _x('Feature', 'post type singular name'),<br />
		'add_new' =&gt; _x('Add New', 'Feature item'),<br />
		'add_new_item' =&gt; __('Add New Feature'),<br />
		'edit_item' =&gt; __('Edit Feature Item'),<br />
		'new_item' =&gt; __('New Feature Item'),<br />
		'view_item' =&gt; __('View Feature Item'),<br />
		'search_items' =&gt; __('Search Feature'),<br />
		'not_found' =&gt;  __('Nothing found'),<br />
		'not_found_in_trash' =&gt; __('Nothing found in Trash'),<br />
		'parent_item_colon' =&gt; ''<br />
	);</p>
<p>	$args = array(<br />
		'labels' =&gt; $labels,<br />
		'public' =&gt; true,<br />
		'publicly_queryable' =&gt; true,<br />
		'show_ui' =&gt; true,<br />
		'query_var' =&gt; true,<br />
		'rewrite' =&gt; false,<br />
		'capability_type' =&gt; 'post',<br />
		'hierarchical' =&gt; false,<br />
		'has_archive' =&gt; true,<br />
		'menu_position' =&gt; null,<br />
		'supports' =&gt; array('title','editor','thumbnail', 'comments','trackbacks', 'author'),<br />
		'taxonomies' =&gt; array('post_tag'),<br />
	  ); </p>
<p>	register_post_type( 'feature' , $args );<br />
}</p>
<p>// add to our plugin init function<br />
global $wp_rewrite;<br />
$feature_structure = '/features/%year%/%monthnum%/%day%/%postname%';<br />
$wp_rewrite-&gt;add_rewrite_tag("%feature%", '([^/]+)', "feature=");<br />
$wp_rewrite-&gt;add_permastruct('feature', $feature_structure, false);<br />
</code></p>
<p>Any help appreciated, thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ShibaShake</title>
		<link>http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2#comment-10993</link>
		<dc:creator>ShibaShake</dc:creator>
		<pubDate>Wed, 25 Jan 2012 18:56:08 +0000</pubDate>
		<guid isPermaLink="false">http://shibashake.com/wordpress-theme/?p=6451#comment-10993</guid>
		<description>http://shibashake.com/wordpress-theme/add-custom-taxonomy-tags-to-your-wordpress-permalinks</description>
		<content:encoded><![CDATA[<p><a href="http://shibashake.com/wordpress-theme/add-custom-taxonomy-tags-to-your-wordpress-permalinks" rel="nofollow">http://shibashake.com/wordpress-theme/add-custom-taxonomy-tags-to-your-wordpress-permalinks</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xevo</title>
		<link>http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2#comment-10977</link>
		<dc:creator>Xevo</dc:creator>
		<pubDate>Wed, 25 Jan 2012 08:19:16 +0000</pubDate>
		<guid isPermaLink="false">http://shibashake.com/wordpress-theme/?p=6451#comment-10977</guid>
		<description>Already solved this and it is possible, however when visiting the url, it gives a 404.

I checked the comments, but could not find a good solution for this.</description>
		<content:encoded><![CDATA[<p>Already solved this and it is possible, however when visiting the url, it gives a 404.</p>
<p>I checked the comments, but could not find a good solution for this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xevo</title>
		<link>http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2#comment-10955</link>
		<dc:creator>Xevo</dc:creator>
		<pubDate>Tue, 24 Jan 2012 17:30:55 +0000</pubDate>
		<guid isPermaLink="false">http://shibashake.com/wordpress-theme/?p=6451#comment-10955</guid>
		<description>Hi, nice article, but is it possible to use a custom post meta in the permalink?</description>
		<content:encoded><![CDATA[<p>Hi, nice article, but is it possible to use a custom post meta in the permalink?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amanda</title>
		<link>http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2#comment-9560</link>
		<dc:creator>Amanda</dc:creator>
		<pubDate>Wed, 21 Dec 2011 22:03:55 +0000</pubDate>
		<guid isPermaLink="false">http://shibashake.com/wordpress-theme/?p=6451#comment-9560</guid>
		<description>Sorry, I wrote too soon! I saw you already answered it in the previous comments and that worked for me too. Thanks again for the great info!</description>
		<content:encoded><![CDATA[<p>Sorry, I wrote too soon! I saw you already answered it in the previous comments and that worked for me too. Thanks again for the great info!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amanda</title>
		<link>http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2#comment-9559</link>
		<dc:creator>Amanda</dc:creator>
		<pubDate>Wed, 21 Dec 2011 21:59:35 +0000</pubDate>
		<guid isPermaLink="false">http://shibashake.com/wordpress-theme/?p=6451#comment-9559</guid>
		<description>Thanks for the info! It worked great to change the permalinks on my custom post type, but I am getting a 404 when I try to view the post? Is there something I&#039;m missing? I&#039;ve tried saving the Permalinks Settings Page, but that hasn&#039;t done anything. Thanks in advance!</description>
		<content:encoded><![CDATA[<p>Thanks for the info! It worked great to change the permalinks on my custom post type, but I am getting a 404 when I try to view the post? Is there something I&#8217;m missing? I&#8217;ve tried saving the Permalinks Settings Page, but that hasn&#8217;t done anything. Thanks in advance!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 14/35 queries in 1.363 seconds using disk: basic
Object Caching 490/530 objects using disk: basic

Served from: shibashake.com @ 2012-05-15 11:09:22 -->
