<?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>Mike Van WinkleRemove the Admin Bar for Non-admin Users | Mike Van Winkle</title>
	<atom:link href="http://www.mikevanwinkle.com/category/wordpress/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikevanwinkle.com</link>
	<description>Wordpress/PHP Developer</description>
	<lastBuildDate>Tue, 31 Jan 2012 00:02:30 +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>Remove the Admin Bar for Non-admin Users</title>
		<link>http://www.mikevanwinkle.com/wordpress/remove-the-admin-bar-for-non-admin-users/</link>
		<comments>http://www.mikevanwinkle.com/wordpress/remove-the-admin-bar-for-non-admin-users/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 20:44:30 +0000</pubDate>
		<dc:creator>Mike Van Winkle</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.mikevanwinkle.com/?p=1204</guid>
		<description><![CDATA[if(!current_user_can('administrator')) { add_filter('show_admin_bar','__return_false'); remove_action('wp_head','_admin_bar_bump_cb'); }]]></description>
			<content:encoded><![CDATA[<pre class="brush:php">
		if(!current_user_can('administrator')) {
			add_filter('show_admin_bar','__return_false');
			remove_action('wp_head','_admin_bar_bump_cb');
		}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mikevanwinkle.com/wordpress/remove-the-admin-bar-for-non-admin-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress $current_user Global Changed in WordPress 3.3</title>
		<link>http://www.mikevanwinkle.com/wordpress/wordpress-current_user-global-changed-in-wordpress-3-3/</link>
		<comments>http://www.mikevanwinkle.com/wordpress/wordpress-current_user-global-changed-in-wordpress-3-3/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 03:00:00 +0000</pubDate>
		<dc:creator>Mike Van Winkle</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.mikevanwinkle.com/?p=1189</guid>
		<description><![CDATA[WordPress has been slowly changing their global $current_user object and the changes in WordPress 3.3 broke my Simplr Registration Form Plus plugin and probably a few others. For any other developers trying to investigate why usermeta field values disappear it is because: global $current_user; This was used to return an object containing not only the [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress has been slowly changing their global $current_user object and the changes in WordPress 3.3 broke my <a href="/simplr-registration-form-plus">Simplr Registration Form Plus</a> plugin and probably a few others. For any other developers trying to investigate why usermeta field values disappear it is because:</p>
<pre class="brush:php">global $current_user;</pre>
<p>This was used to return an object containing not only the primary user fields but all the meta fields as well. So if you set a user meta field called &#8220;age&#8221; you could simply do:</p>
<pre class="brush:php">
global $current_user;
if($current_user->data->age > 21) {
  // the do some adult stuff;
}
</pre>
<p>But this shortcut is no longer available to developers and for good reason. As a general rule code should be efficient, meaning it does only what it has to. To load even the most superflous meta fields every time you access the basic user object is a waste of resources. </p>
<p>So good for WordPress, they are improving. But there are likely others like me who figured if WordPress was going to give me the info, then I was going to use it. And like me they&#8217;ll have to spend all day tracking down everywhere they used this shortcut and fixing it. Ugh. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikevanwinkle.com/wordpress/wordpress-current_user-global-changed-in-wordpress-3-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Simplest WordPress User Access Log Ever</title>
		<link>http://www.mikevanwinkle.com/geek-think/the-simplest-wordpress-user-access-log-ever/</link>
		<comments>http://www.mikevanwinkle.com/geek-think/the-simplest-wordpress-user-access-log-ever/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 14:41:16 +0000</pubDate>
		<dc:creator>Mike Van Winkle</dc:creator>
				<category><![CDATA[Geek Think]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Pods]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[podscms]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.mikevanwinkle.com/?p=1101</guid>
		<description><![CDATA[Those of use who develop using pods often find we use it for everything. So here&#8217;s a quick tip on using PodsCMS to create a custom user access log. Step 1: Set up the Pod I&#8217;m assuming you&#8217;ve already installed/activate both the PodsCMS and Pods UI plugins. If not, please do so before starting. Create [...]]]></description>
			<content:encoded><![CDATA[<p>Those of use who develop using pods often find we use it for everything. So here&#8217;s a quick tip on using PodsCMS to create a custom user access log.</p>
<h2>Step 1: Set up the Pod</h2>
<p>I&#8217;m assuming you&#8217;ve already installed/activate both the PodsCMS and Pods UI plugins. If not, please do so before starting. </p>
<p>Create a new Pod called &#8220;logins&#8221;.<br />
<a href="http://www.mikevanwinkle.com/wp-content/uploads/2011/06/Screen-shot-2011-06-29-at-10.15.54-AM.png"><img src="http://www.mikevanwinkle.com/wp-content/uploads/2011/06/Screen-shot-2011-06-29-at-10.15.54-AM-300x180.png" alt="" title="Screen shot 2011-06-29 at 10.15.54 AM" width="300" height="180" class="alignnone size-medium wp-image-1105" /></a></p>
<p>By default each pod is created with a name and slug field. We&#8217;re going to use the name field but you can delete the slug field. </p>
<p>Then you&#8217;ll need to create a field for &#8220;date&#8221;. Of course, Pods stores the date any entry is created in a field called &#8220;created&#8221; which you can access from within Pods Templates. But it still makes sense to have a date field in the Pod itself, if nothing else for the sake of a clear data model. </p>
<p><a href="http://www.mikevanwinkle.com/wp-content/uploads/2011/06/Screen-shot-2011-06-29-at-10.16.46-AM.png"><img src="http://www.mikevanwinkle.com/wp-content/uploads/2011/06/Screen-shot-2011-06-29-at-10.16.46-AM-247x300.png" alt="" title="Screen shot 2011-06-29 at 10.16.46 AM" width="247" height="300" class="alignnone size-medium wp-image-1106" /></a> </p>
<p>So once you have added the date field your Pod will look like this:</p>
<p><a href="http://www.mikevanwinkle.com/wp-content/uploads/2011/06/Screen-shot-2011-06-29-at-10.17.03-AM.png"><img src="http://www.mikevanwinkle.com/wp-content/uploads/2011/06/Screen-shot-2011-06-29-at-10.17.03-AM-300x172.png" alt="" title="Screen shot 2011-06-29 at 10.17.03 AM" width="300" height="172" class="alignnone size-medium wp-image-1107" /></a></p>
<h2>Step 2: Add function</h2>
<p>Now just add the following code to your functions.php file. </p>
<pre class="brush:php">
add_action('set_logged_in_cookie','mpv_add_access_log_entry');
function mpv_add_access_log_entry($user) {
	$user = explode('|',$user);
	$log = new PodAPI();
	$params = array('datatype'=>'logins');
	$params['columns'] = array('name'=>$user[0],'date'=>date('Y-m-d H:i:s'));
	$log->save_pod_item(pods_sanitize($params));
}
</pre>
<p>This function uses the Pod API to insert a row in the logins table. Alternatively you can use the $wpdb class and do something like this: </p>
<pre class="brush:php">
global $wpdb;
$wpdb->insert($wpdb->prefix.'pod_tbl_logins',array('name'=> $user[0],'date'=> date('Y-m-d H:i:s')));
</pre>
<p>The only trouble with going this route is that in order to use the pods admin interface to manage the data, you&#8217;ll also need to add a row to the wp_pod table. This will change with Pods 2.0 so there&#8217;s no need to demonstrate. But I strongly recommend using the PodsAPI class as it will make sure to implement best practices and in 2.0 it will use the $wpdb class anyway. </p>
<p>So that&#8217;s it. To create an exportable report of the logins just install the &#8220;<a href="http://wordpress.org/extend/plugins/exports-and-reports/">Exports and Reports</a>&#8221; plugin. Or you can use PodsUI to create a custom interface. </p>
<p>Have fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikevanwinkle.com/geek-think/the-simplest-wordpress-user-access-log-ever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Hack #1: Global Meta Variable for Custom Fields</title>
		<link>http://www.mikevanwinkle.com/geek-think/wordpress-hack-1-global-meta-variable-for-custom-fields/</link>
		<comments>http://www.mikevanwinkle.com/geek-think/wordpress-hack-1-global-meta-variable-for-custom-fields/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 17:55:01 +0000</pubDate>
		<dc:creator>Mike Van Winkle</dc:creator>
				<category><![CDATA[Geek Think]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.mikevanwinkle.com/?p=788</guid>
		<description><![CDATA[A WordPress theme hack for displaying custom field values.]]></description>
			<content:encoded><![CDATA[<p>This is the first in what I hope will be a series of posts on &#8220;WordPress Hacks&#8221;, simple code you can add to functions.php to make your life as a developer a little easier. </p>
<p>Ever get tired of typing <code>get_post_meta($post->ID, $meta_key, $true);</code>  to fetch even the simplest of WordPress custom field values. Try this. </p>
<pre class="brush:php">
add_action('the_post','setup_meta_var');
function setup_meta_var() {
	global $wp_query,$meta;
	$vals = get_post_custom($data->ID);
	foreach($vals as $k => $v)
	{
		if(count($v) > 1):
			$meta[$k] = $v;
		else:
			$meta[$k] = $v[0];
		endif;
	}
}
</pre>
<p>What this dandy little function does is automatically assign a post or page&#8217;s custom values to a global variable call <code>$meta</code>.</p>
<p>To use your custom field values now, you simply have the do echo the meta_key like so:</p>
<pre class="brush:php">
global $meta;
echo $meta['meta_key'];
</pre>
<p>If there is more than one value for that custom field, you will simply need to do a standard foreach loop. </p>
<pre class="brush:php">
global $meta;
foreach($meta['meta_key'] as $m) {
echo $m;
}
</pre>
<p><em>Update: Hey, I realized that in the code snippet I pasted here I was setting a <code>$type</code> variable. That was a relic of the custom script this code was taken from &#8230; so please ignore. </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikevanwinkle.com/geek-think/wordpress-hack-1-global-meta-variable-for-custom-fields/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using WordPress Pods to Manage Custom Data</title>
		<link>http://www.mikevanwinkle.com/wordpress/using-wordpress-pods-to-manage-custom-data/</link>
		<comments>http://www.mikevanwinkle.com/wordpress/using-wordpress-pods-to-manage-custom-data/#comments</comments>
		<pubDate>Tue, 11 Jan 2011 19:21:11 +0000</pubDate>
		<dc:creator>Mike Van Winkle</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Pods]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.mikevanwinkle.com/?p=774</guid>
		<description><![CDATA[Last week I posted about relating a WordPress post to your Pods data. But I realize, for a lot of people, the question is still: Why use Pods to manage your custom data in the first place? There are a ton of benefits to using PodsCMS. Here&#8217;s a thread worth reading on the forum. But [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I posted about <a href="http://www.mikevanwinkle.com/wordpress/down-and-dirty-wordpress-pods-related-content/">relating a WordPress post to your Pods data</a>. But I realize, for a lot of people, the question is still: Why use Pods to manage your custom data in the first place? </p>
<p>There are a ton of benefits to using PodsCMS. Here&#8217;s a <a href="http://podscms.org/qna/questions/1552/general-question-why-choose-podscms-and-not-custom-post-types-procontra">thread worth reading</a> on the forum. But I thought it might be helpful to see an example. </p>
<p>Let&#8217;s go back to our <a href="http://www.mikevanwinkle.com/wordpress/down-and-dirty-wordpress-pods-related-content/">related books tutorial</a>. Why couldn&#8217;t we do this using custom fields and custom post types? That would be simple enough. We&#8217;d first create a post type called &#8220;books&#8221;. Then we&#8217;d need to create a meta box that would add the post ID of the related book to our post. </p>
<p>No big deal. We could easily query the related books lik so (I am not testing this code, so don&#8217;t try and reuse. This is purely for example):</p>
<pre class="brush:php">
$bookid = get_post_meta($post->ID,'related_books', false);
$args = array('post__in' => $bookid, 'post_type' => 'books');
$books = new WP_query($args);
</pre>
<p>Then of course, we&#8217;d use a while loop: </p>
<pre class="brush:php">
while($books->have_posts()) : $books->the_post();
</pre>
<p>Pretty simple. But what happens when we start adding complexity? What if we want to feature books that are either related by ID, or have a certain author? </p>
<p>Let&#8217;s assume for the moment that we&#8217;re using a custom field to save the author name in the books post type. This scenario is a little more challenging. The query above is restrictive to books that have been selected as related. But since we want to do an &#8220;OR&#8221; query we&#8217;re probably going to need a custom select query:</p>
<pre class="brush:php">
global $wpdb;
$id = $post->ID; //the current post id
$query = "SELECT DISTINCT p.ID FROM wp_posts p INNER JOIN wp_postmeta AS m ON p.ID =  m.post_id WHERE p.post_type = 'books' AND p.post_status = 'publish' AND ( (m.meta_key = 'book_author' AND m.meta_value = 'William Shakespeare') OR p.ID IN(SELECT DISTINCT meta_value FROM wp_postmeta WHERE meta_key = 'related_book' AND post_id = '$id') )";
$results = $wpdb->get_col($query);
</pre>
<p>In theory this custom select query gets us an array of post IDs we can then pass on to the standard WP query using the <em>post__in</em> argument we used above. Notice that just a modest increase in the complexity of the request leads to <em>major</em> increase in the complexity of the query. </p>
<p>But what if we are using a post_type for authors and need all the authors who have written certain kinds of books. Say we have a category &#8220;childrens books&#8221; and we want to get a list of all authors who have written a children&#8217;s book. This is where WordPress starts to get pretty convoluted. We could use a custom select query, like we did before. But we could also combine some WP queries.</p>
<pre class="brush:php">
//get the books in the childrens book category
$cbooks = get_posts('post_type=books&#038;category_name=Childrens Books');
foreach($cbooks as $cbook) {
  $cids[] = $cbook->ID;
}
$authors = query_posts(array('post_type'=>'author','post__in'=>$cids));
?>
</pre>
<p>This is a a pretty inefficient use of code and it only get worse. Imagine needing to see a list of books in a certain category, with a certain author, with a certain number of pages, that was written in 2010. </p>
<p>You&#8217;re using custom fields for the publication year and the pages, a custom post_type for author and a category for the genre. Think of the mental power that will go into putting this query together. You&#8217;ll have to do a custom select query.</p>
<pre class="brush:php">
global $wpdb;
$query = "
SELECT DISTINCT ID FROM wp_posts p
INNER JOIN wp_term_relationships AS tr ON tr.object_id = p.ID
INNER JOIN wp_term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
INNER JOIN wp_terms AS t ON t.term_id = tt.term_id
INNER JOIN wp_postmeta AS m1 ON m1.post_id = p.ID AND m1.meta_key = 'related_author'
INNER JOIN wp_postmeta AS m2 ON m2.post_id = m1.post_id AND m2.meta_key = 'publication_year'
INNER JOIN wp_postmeta AS m3 ON m3.post_id = m2.post_id AND m3.meta_key = 'num_pages'
WHERE p.post_status = 'publish' AND p.post_type = 'books'
AND t.slug = 'childrens-books'
AND m1.meta_value = 'William Shakespeare'
AND m2.meta_value = '2010'
AND m3.meta_value > 200
ORDER BY p.post_title ASC
";
$results = $wpdb->get_col($query);
query_posts(array('post__in'=>$results));
</pre>
<p>I&#8217;m not even sure if this query would work, but the query that would work would look a lot like this. </p>
<p>So you get the point. WordPress has no method of simplifying complex queries. </p>
<p>If you are the client and know exactly how you plan to use your site then this isn&#8217;t such a big worry. But if you&#8217;re a developer working for a client using WordPress as a CMS, you don&#8217;t know what the client might eventually request.  Nevertheless, it&#8217;s your job to be able to meet that request. </p>
<p>Pods is a CMS framework built specifically to deal with these complexities. Let&#8217;s perform the query above using the Pods approach. </p>
<pre class="brush:php">
$pod = new Pod('books');
$pod->findRecords('name ASC',-1, "author.name = 'William Shakespeare' AND t.year = '2010' AND t.pages > 200 AND cat.slug = 'childrens-books'");
echo $pod->showTemplate('book_list');
</pre>
<p>Seriously, that&#8217;s it. And of course, you could substitute &#8220;OR&#8221; for any of the &#8220;AND&#8221; operators above to get a more inclusive result. </p>
<p>Pods gets a lot of criticism for being a WordPress hack. If you can do what you want to do with WordPress why introduce an unnecessary plugin? I hope I&#8217;ve demonstrated here that the advantages to using the PodsCMS Framework are enormous in terms of time and mental energy saved. </p>
<p>And it&#8217;s key to remember that Pods is a development Framework, not really a plugin. It can be used to manage minor amounts of custom data in your WordPress posts or a complex web of related content types that are outside of the Posts system altogether. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikevanwinkle.com/wordpress/using-wordpress-pods-to-manage-custom-data/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Down and Dirty WordPress Pods Related Content</title>
		<link>http://www.mikevanwinkle.com/wordpress/down-and-dirty-wordpress-pods-related-content/</link>
		<comments>http://www.mikevanwinkle.com/wordpress/down-and-dirty-wordpress-pods-related-content/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 23:04:49 +0000</pubDate>
		<dc:creator>Mike Van Winkle</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Pods]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.mikevanwinkle.com/?p=727</guid>
		<description><![CDATA[Update: Looking at this now, I realized there are some advantages to taking a slightly different approach. This thread at PodsCMS.org asks how to relate posts to Pods content. This is something that will get easier in future versions of pods. But the beauty of Pods is that it&#8217;s already pretty damn easy if you [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update: Looking at this now, I realized there are some advantages to taking a slightly different approach. </strong></p>
<p>This thread at PodsCMS.org asks how to relate posts to Pods content. This is something that will get easier in future versions of pods. But the beauty of Pods is that it&#8217;s already pretty damn easy if you are familiar with how WordPress manages custom fields.</p>
<p>Getting Down!</p>
<p>So let&#8217;s say you have a pod called &#8220;books&#8221; and you want to be able to relate blog posts to the books you are organizing via pods. I&#8217;m going to assume for the sake of this tutorial that you already know how to create Pods content and so you&#8217;ll have no problem with the first step:</p>
<p><strong>1. Books pod:</strong></p>
<p><a href="http://www.mikevanwinkle.com/wp-content/uploads/2011/01/Screen-shot-2011-01-04-at-9.12.13-AM.png"><img class="size-medium wp-image-733 alignnone" title="Screen shot 2011-01-04 at 9.12.13 AM" src="http://www.mikevanwinkle.com/wp-content/uploads/2011/01/Screen-shot-2011-01-04-at-9.12.13-AM-300x248.png" alt="" width="300" height="248" /></a></p>
<p><strong>2. Posts pod.</strong></p>
<p>Next you&#8217;ll want to set up a pod to relate to posts, you might call it &#8220;posts&#8221;, or &#8220;post_relations&#8221;, or &#8220;post_meta&#8221;:<br />
<a href="http://www.mikevanwinkle.com/wp-content/uploads/2011/01/Screen-shot-2011-01-04-at-5.13.49-PM.png"><img class="alignnone size-medium wp-image-741" title="Screen shot 2011-01-04 at 5.13.49 PM" src="http://www.mikevanwinkle.com/wp-content/uploads/2011/01/Screen-shot-2011-01-04-at-5.13.49-PM-229x300.png" alt="" width="229" height="300" /></a><br />
Again, if you&#8217;re familiar with Pods this should be pretty straight-forward. Though you might ask why are we creating a pod called &#8220;posts&#8221; when it&#8217;s the books we want to relate to posts. Well we could just relate the books to posts. But the trouble is relating the other way, posts -&gt; books, gets difficult without a pod to store all the relationships. Plus, we might want to add more &#8220;meta&#8221; fields to our posts pod that we can also associate with a post. Basically, if we&#8217;re using pods, we might as well take advantage of the flexibility.</p>
<p>Let&#8217;s also create a pod field called books and make it a pick field related to the books pod.</p>
<p><a href="http://www.mikevanwinkle.com/wp-content/uploads/2011/01/Screen-shot-2011-01-05-at-8.54.10-AM.png"><img src="http://www.mikevanwinkle.com/wp-content/uploads/2011/01/Screen-shot-2011-01-05-at-8.54.10-AM-236x300.png" alt="" title="Screen shot 2011-01-05 at 8.54.10 AM" width="236" height="300" class="alignnone size-medium wp-image-766" /></a></p>
<p>So in our posts pod, we have a pick column relating to posts and one relating to books.</p>
<p><strong>3. Multidirectional?</strong></p>
<p>We can now return to the book pod and set up a &#8220;posts&#8221; field there to relate to the <em>posts pod </em>as a bidirectional field.</p>
<p><a href="http://www.mikevanwinkle.com/wp-content/uploads/2011/01/Screen-shot-2011-01-04-at-5.22.44-PM.png"><img class="alignnone size-medium wp-image-743" title="Screen shot 2011-01-04 at 5.22.44 PM" src="http://www.mikevanwinkle.com/wp-content/uploads/2011/01/Screen-shot-2011-01-04-at-5.22.44-PM-300x158.png" alt="" width="300" height="158" /></a></p>
<p>Why not relate to the posts directly? Again, we want to leverage pods to give us as many options as possible. As long as one pod as is related to posts, we&#8217;re &#8220;plugged&#8221; in so to speak.</p>
<p><strong>4. Create the metabox function:</strong></p>
<p>So here&#8217;s where it gets a little more difficult &#8230; but still not too bad. We&#8217;ll need to create a function that will build the content of our meta box. Add this function to your functions.php.</p>
<pre class="brush:php">
function books_related_pods() {
	global $post;
	echo '
<div id="metabox">';
	echo '
<div class="books-related">';
			$old = new Pod('posts');
			$old->findRecords('id DESC',1,"post.ID = '$post->ID'");
			while($old->fetchRecord()) { $ids[] = $old->get_field('books.id'); }
			if(is_array($ids[0])) { $ids = $ids[0]; }
			echo '
<select name="related_books[]" id="related_books" style="width:80%;height:auto;" multiple="">
<option value="">Select related books ... </option>

';
				$options = new Pod('books');
				$options->findRecords('name ASC',-1);
				while($options->fetchRecord()) {
				$id = $options->get_field('id');
				$sel = (in_array($id,$ids)) ? 'selected' : 'test';
				echo '
<option value="'.$options->get_field('id').'" '.$sel.'="">'.$options->get_field('name').'</option>

';
				}
			echo '</select>

';
		echo '</div>

';
	echo '</div>

';
}
</pre>
<p>Notice that we&#8217;re creating one Pods object as &#8216;$old&#8217; so that we can access the existing values. Then we&#8217;re creating a second as &#8220;options&#8221; which we use to build our select menu options. </p>
<p><strong>5. Create a meta box callback function. </strong><br />
Now we need a function to build the metabox itself. This function will be hooked into the WordPress API. This is an easy one. If you want to know more about meta boxes, read the <a href="http://codex.wordpress.org/Function_Reference/add_meta_box">WordPress Codex article</a>. </p>
<pre class="brush:php">
function books_related_mb() {
	add_meta_box( 'pods_related_mb', "Related Books", 'books_related_pods', 'post', 'normal', 'high', '' );
}
</pre>
<p>Note that the third parameter sets the &#8220;callback&#8221; function for the meta box. In this case we are using function we created above. Also note that the fourth parameter is where you specify the post_type on which you wish to use the meta box.</p>
<p><strong>6. Hook into the WordPress API:</strong></p>
<p>Just add a line in your functions.php:</p>
<pre class="brush:php">add_action('add_meta_boxes','books_related_mb');</pre>
<p>So at this point you should be able to go to your post screen and see the new meta box. If you can&#8217;t your doing something wrong. But we still need to save the meta box.</p>
<p><strong>6. Save the pods!</strong></p>
<p>Now you&#8217;ll see the advantage of the seemingly complicated pods set up. All we have to do is find the post&#8217;s related pod and add the values using the Pods API. </p>
<pre class="brush:php">
add_action('save_post','books_related_save_pod');
function books_related_save_pod($post_id) {
	//
	if( !wp_is_post_revision( $post_id ) &#038;&#038; !wp_is_post_autosave( $post_id ) ) {
        if(isset($_POST['related_books'])) {
				$vals = implode(',',$_POST['related_books']);
				$pod = new Pod('posts');
				$pod->findRecords('id DESC',1,"post.ID = '$post_id'" );
				while($pod->fetchRecord()) {
					$pid = $pod->get_pod_id();
					}
				if($pid) {

					//if a pod exists, save the values
					$api = new PodAPI();
					$params = array();
					$params['datatype'] = 'posts';
					$params['pod_id'] = $pid;
					$params['columns']['books'] = $vals;
					$params = pods_sanitize($params);
					$api->save_pod_item($params);

				} else {

					$new = new PodAPI();
					$params = array();
					$params['datatype'] = 'posts';
					$params['columns']['name'] = $_POST['post_title']; 		// You must set a name when saving a new pod
					$params['columns']['post'] = $post_id;
					$params['columns']['books'] = $vals;
					$params = pods_sanitize($params);
					$new->save_pod_item($params);
				}				

		}
           }
	}
?>
</pre>
<p>So there you have it. Down and dirty. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikevanwinkle.com/wordpress/down-and-dirty-wordpress-pods-related-content/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Flutter to Custom Post Types</title>
		<link>http://www.mikevanwinkle.com/wordpress/flutter-to-custom-post-types/</link>
		<comments>http://www.mikevanwinkle.com/wordpress/flutter-to-custom-post-types/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 16:06:51 +0000</pubDate>
		<dc:creator>Mike Van Winkle</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[flutter]]></category>
		<category><![CDATA[wordpress as cms]]></category>

		<guid isPermaLink="false">http://www.mikevanwinkle.com/?p=720</guid>
		<description><![CDATA[So I&#8217;m working a project right now where I&#8217;m converting a WordPress installation from Flutter to the native WordPress custom post type functionality. The reasons for the switch are numerous. For one, it&#8217;s always good rule of thumb to use as few plugins as possible. The fewer plugins, the fewer php warning messages, the fewer [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;m working a project right now where I&#8217;m converting a WordPress installation from Flutter to the native WordPress custom post type functionality. The reasons for the switch are numerous. For one, it&#8217;s always good rule of thumb to use as few plugins as possible. The fewer plugins, the fewer php warning messages, the fewer javascript conflicts, the fewer hooks and filters getting processed on every load, and the fewer hits on the Database server. Secondly, flutter is particularly hard on the database, sometimes adding an extra 5 or more queries for every custom field.</p>
<p>The really great thing about flutter is that it still stores the field values in the  <span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">wp_postmeta </span>table which means you don&#8217;t have to worry about any real data migration. So you have the luxury of taking it a step at a time.</p>
<p>The first step is to convert those key categories attached to &#8220;write panels&#8221; into post types. I did this by <a title="Wordpress Codex" href="http://codex.wordpress.org/Function_Reference/register_post_type">registering the post type</a> as usual and simply running the following function on the init hook. This function performs a simple DB query to update posts with the specified cat slug into post_types.</p>
<p><code><br />
function convert_cats_to_types($cat,$type) {<br />
global $wpdb;<br />
$query = $wpdb-&gt;prepare("<br />
UPDATE wp_posts SET post_type = '$type' WHERE ID IN<br />
(<br />
SELECT DISTINCT object_id FROM wp_term_relationships rel<br />
INNER JOIN wp_term_taxonomy AS tt ON tt.term_taxonomy_id = rel.term_taxonomy_id AND tt.taxonomy = 'category'<br />
INNER JOIN wp_terms AS t ON t.term_id = tt.term_id AND t.slug = '$cat'<br />
)<br />
");<br />
$results = $wpdb-&gt;query($query);<br />
}</code></p>
<p>There&#8217;s no risk of losing data here, we are just changing where the posts in question are show up. The second thing to do is to replace the field-specific metaboxes. We&#8217;ll cover that in the next post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikevanwinkle.com/wordpress/flutter-to-custom-post-types/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Registration Forms: What&#8217;s New in 1.5</title>
		<link>http://www.mikevanwinkle.com/wordpress/registration-forms-whats-new-in-1-5/</link>
		<comments>http://www.mikevanwinkle.com/wordpress/registration-forms-whats-new-in-1-5/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 13:23:45 +0000</pubDate>
		<dc:creator>Mike Van Winkle</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[Registration Forms]]></category>
		<category><![CDATA[user management]]></category>
		<category><![CDATA[wordpress as cms]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://www.mikevanwinkle.com/?p=628</guid>
		<description><![CDATA[Last week I released version 1.5 of my Simplr Registration Forms plugin. The new version includes some big fixes and requested features. Particularly, this version now supports WP Multisite and has a few addition profile fields that can be added to the default form. It also includes better security, via WP nonces, and better field [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I released version 1.5 of my <a title="WordPress registration forms" href="http://www.mikevanwinkle.com/wordpress/custom-wordpress-registration-page/">Simplr Registration Forms</a> plugin. The new version includes some big fixes and requested features. Particularly, this version now supports WP Multisite and has a few addition profile fields that can be added to the default form. It also includes better security, via WP nonces, and better field validation.</p>
<p>But the most important change is that it includes hooks and filters that allow it to be extended by you, the user.</p>
<p>For instance, let&#8217;s add a field to our form that requests the user&#8217;s zip code. First, in your functions.php file create a function for displaying the field:</p>
<pre>function sample_zip_field($form) {
 $form .=  '&lt;div&gt;';
 $form .=  '&lt;label for="zip"&gt;Zip Code:&lt;/label&gt;';
 $form .=  '&lt;input type="text" name="zip" value="'.$_POST['zip'] .'"/&gt;&lt;br/&gt;';
 $form .=  '&lt;/div&gt;';
 return $form;
}
</pre>
<p>Note that this function receives the parameter $form and then returns $form. Failing to return the form will make the entire registration form disappear. To add this form to the registration use:</p>
<pre>add_filter('simplr_add_form_fields', 'sample_zip_field');
</pre>
<p>But then we also need to make sure this data gets saved when the for gets saved. So you&#8217;ll need to create a function for that as well.</p>
<pre>function sample_save_meta($user_id) {
if(isset($_POST['zip'])) {
 add_user_meta($user_id, 'user_zip', $_POST['zip']);
 }
return $user_id;
}
</pre>
<p>Note that in order for this function to work properly it has to receive the $user_id. It is also good practice to return the $user_id at the end of the function, though not necessary.</p>
<p>To make sure your save function is called use the hook:</p>
<pre>add_action('simplr_profile_save_meta','sample_save_meta');
</pre>
<p>With these two &#8220;hooks&#8221;, you can customize the registration form however you want. You could even set up your field function to only display on certain pages, making it form-specific.</p>
<p>Finally, I&#8217;ve also added filters to the labels on the default form fields so you can change them at will. For instance, to change username to &#8220;screen name&#8221; use the following.</p>
<pre>function sample_label_username($label) {
 $label = "Screen name: ";
 return $label;
}
add_filter('simplr_label_username','sample_label_username');
</pre>
<p>I hope you find the changes useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikevanwinkle.com/wordpress/registration-forms-whats-new-in-1-5/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Custom WordPress Registration Pages (v 0.1.7)</title>
		<link>http://www.mikevanwinkle.com/wordpress/custom-wordpress-registration-page/</link>
		<comments>http://www.mikevanwinkle.com/wordpress/custom-wordpress-registration-page/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 20:45:15 +0000</pubDate>
		<dc:creator>Mike Van Winkle</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.mikevanwinkle.com/?p=394</guid>
		<description><![CDATA[Key Links: WordPress Link: Simplr Registration Form Plugin API Documentation: Hooks and Filters in 1.5+ Premium Version: Includes easy field creation and ReCaptcha spam protection. Installation Instructions: Download and unzip the package. Upload the simplr_reg_page folder into your wp-content/plugins directory. Go to your plugins dashboard and click &#8220;Activate&#8221;. Usage Instructions: To use this plugin simply [...]]]></description>
			<content:encoded><![CDATA[Registrations have been disabledRegistrations have been disabledRegistrations have been disabledRegistrations have been disabled<p>Key Links:</p>
<ul>
<li><strong>WordPress Link:</strong> <a href="http://tinyurl.com/3y7ev4c">Simplr Registration Form Plugin</a></li>
<li><strong>API Documentation:</strong> <a title="Registration Form API" href="http://www.mikevanwinkle.com/wordpress/registration-forms-whats-new-in-1-5/">Hooks and Filters in 1.5+</a></li>
<li><strong>Premium Version:</strong> <a title="Simplr WordPress Registration Form Plus" href="http://www.mikevanwinkle.com/simplr-registration-form-plus/">Includes easy field creation and ReCaptcha spam protection.</a></li>
</ul>
<p><strong>Installation Instructions:</strong></p>
<p>Download and unzip the package. Upload the simplr_reg_page folder into your wp-content/plugins directory. Go to your plugins dashboard and click &#8220;Activate&#8221;.</p>
<p><strong>Usage Instructions:</strong></p>
<p>To use this plugin simply employ the shortcode <code></code> on any WordPress post or page. The default role is &#8220;subscriber&#8221;. To apply another role to the registration simply use the the role parameter, for instance: <code></code>. If you have created custom roles you may use them as well.</p>
<p>You can also use shortcode so specify a custom confirmation message for each form:</p>
<p><code></code></p>
<p>Finally, you can specify emails to be notified when a new user is registered. By default site admins will receive notice but to notify others simply use the notify parameter:</p>
<p><code></code></p>
<p><strong>Plugin Options:</strong></p>
<p>Please feel free to suggest future options for this plugin in the comments. The current options are:</p>
<ul>
<li>Admin Email: Specify the FROM email you would like to use for the registration confirmation message.</li>
<li>Confirmation Message: Customize the message you would like to appear in the confimation email.</li>
<li>Style: Overrides the default stylesheet included with the plugin.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.mikevanwinkle.com/wordpress/custom-wordpress-registration-page/feed/</wfw:commentRss>
		<slash:comments>179</slash:comments>
		</item>
		<item>
		<title>Introduction to WordPress Pods CMS</title>
		<link>http://www.mikevanwinkle.com/wordpress/introduction-to-wordpress-pods-cms/</link>
		<comments>http://www.mikevanwinkle.com/wordpress/introduction-to-wordpress-pods-cms/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 11:51:50 +0000</pubDate>
		<dc:creator>Mike Van Winkle</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.mikevanwinkle.com/?p=604</guid>
		<description><![CDATA[Scott Clark, the tireless developer of Pods CMS, has put together a tutorial on using PodsCMS. Where does he find the time. Introduction to the Pods CMS Framework from Pods CMS Framework on Vimeo. In this video, Scott Kingsley Clark gives an introduction to the Pods CMS Framework. He goes over what Pods is, setting [...]]]></description>
			<content:encoded><![CDATA[<p>Scott Clark, the tireless developer of <a href="http://www.podscms.org">Pods CMS</a>, has put together a tutorial on using PodsCMS. Where does he find the time. </p>
<p><iframe src="http://player.vimeo.com/video/15086927?color=ff9933" width="500" height="300" frameborder="0"></iframe>
<p><a href="http://vimeo.com/15086927">Introduction to the Pods CMS Framework</a> from <a href="http://vimeo.com/user4656327">Pods CMS Framework</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>In this video, Scott Kingsley Clark gives an introduction to the Pods CMS Framework. He goes over what Pods is, setting up your Pods and displaying them on your site, and provides some helpful tips and pointers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikevanwinkle.com/wordpress/introduction-to-wordpress-pods-cms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Object Caching 735/818 objects using apc

Served from: www.mikevanwinkle.com @ 2012-02-04 20:10:30 -->
