<?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>WP Engineer &#187; Custom Fields</title>
	<atom:link href="http://wpengineer.com/tag/custom-fields/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Mon, 21 May 2012 22:48:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Control WordPress Nav Menu via Custom Fields</title>
		<link>http://wpengineer.com/2116/control-wordpress-nav-menu-custom-fields/</link>
		<comments>http://wpengineer.com/2116/control-wordpress-nav-menu-custom-fields/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 11:22:30 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[Custom Fields]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2116</guid>
		<description><![CDATA[WordPress 3.0 also includes the menus, in addition to a number of other new features. Normally you generate a menu automatically by creating pages, but under Appereance / Menus you can create your own menu and assign a place where it replaces the normal menu. But whoever currently uses WordPress as a CMS and blog [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://wpengineer.com/wp-content/uploads/WordPress-Christmas-2010-15.jpg" alt="" title="WordPress-Christmas-2010-15" width="400" height="267" class="aligncenter size-full wp-image-2136" /><br />
WordPress 3.0 also includes the <strong>menus</strong>, in addition to a number of other new features. Normally you generate a menu automatically by creating pages, but under Appereance / Menus you can create your own menu and assign a place where it replaces the normal menu.</p>
<p>But whoever currently uses WordPress as a CMS and blog (like me) may now have a problem: If you look at the blog you should be able to see the normal pages in the navigation, but if you then select a page with many subpages it would be nice if the subpages were listed in the menu bar as well as listing only one entry "Blog" which brings you back to the blog page.</p>
<p><img src="http://wpengineer.com/wp-content/uploads/WP_Menü.png" alt="" title="WP_Menü" width="382" height="164" class="aligncenter size-full wp-image-2117" /></p>
<p>Conveniently, WordPress already includes everything you need to put together this idea. They are on the one hand of course the aforementioned menus, and on the other side there are Custom Fields. If you have not hidden, you can find at every post and every page an editor where you can enter meta data. Via this meta data and with the help of a small code snippet you can control what is displayed in the menu.</p>
<p>You can put the code snippet in your <code>functions.php</code> of your Theme or in a Plugin.</p>
<pre>
//Filter the arguments for the wp_nav_menu_function to include a custom menu on pages.
function nr_2010_wp_nav_menu_args($args = &#039;&#039;)
{
	if ( is_page() ) //custom menus only on sites
	{
		global $post;

		$menu_name = get_post_meta($post-&gt;ID, &#039;menu_name&#039;, true);

		if( !empty($menu_name) &amp;&amp; is_nav_menu($menu_name) )
		{
			$args&#091;&#039;menu&#039;&#093; = $menu_name;
		}
	}
	return $args;
}
add_filter( &#039;wp_nav_menu_args&#039;, &#039;nr_2010_wp_nav_menu_args&#039; );
</pre>
<p>This code puts a filter on <code>wp_nav_menu_args</code>, these are the parameters of the function <code>wp_nav_menu</code>, which the Theme uses to output the menus.</p>
<p>As long as we are on a page (<code>is_page()</code>) the custom field <code>menu_name</code> will be used. If it's not empty and it has a menu with this name, the paramaters of this call will be modified, so it shows the right menu.</p>
<p>Only one thing left: Provide the correct meta data to the pages and create the corresponding menus. The menu editor is very intuitive, it shouldn't be a problem. Just a hint: It doesn't save automatically. <img src='http://wpengineer.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div class="incontent">
<h4>Guest Post</h4>
<p>This post was written by Niklas Rother - <a href="http://niklas-rother.de/">niklas-rother.de</a> and is a post in our Advent Calendar Series on WP Engineer about WordPress.<br />
Thank you very much from my part to <a href="http://niklas-rother.de/">Niklas</a>.<br />
If you also like to have your interesting post published on our website, please let us know on our contact page. Of course we will appreciate your contribution!
</div>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2116/control-wordpress-nav-menu-custom-fields/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sort Posts With The Help Of Custom Fields</title>
		<link>http://wpengineer.com/1915/sort-posts-custom-fields/</link>
		<comments>http://wpengineer.com/1915/sort-posts-custom-fields/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 06:43:33 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[Custom Fields]]></category>
		<category><![CDATA[Sort]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1915</guid>
		<description><![CDATA[Quite often, a WordPress developer likes to have posts sorted according to a custom field. If you would write a SQL-statement, it would be quite complex, since you need to JOIN two database tables (wp_posts und wp_postmeta). But there is a much easier way, if you use the template tags provided by WordPress - in [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://wpengineer.com/wp-content/uploads/WordPress-Christmas-17.jpg" alt="WordPress-Christmas-17" title="WordPress-Christmas-17" width="600" height="400" class="aligncenter size-full wp-image-1895" />Quite often, a WordPress developer likes to have posts sorted according to a custom field. If you would write a SQL-statement, it would be quite complex, since you need to JOIN two database tables (wp_posts und wp_postmeta).</p>
<p>But there is a much easier way, if you use the template tags provided by WordPress - in our case we use the function query_posts. Below you can see an example, which includes a custom field in the query, and also sort the posts with the help of this custom field. A short, easy to understand code with effective result:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/Bildschirmfoto-2009-12-04-um-21.49.05.png" alt="Bildschirmfoto 2009-12-04 um 21.49.05" title="Bildschirmfoto 2009-12-04 um 21.49.05" width="577" height="271" class="aligncenter size-full wp-image-1916" /></p>
<pre lang="php">query_posts(&#039;meta_key=my_day&amp;meta_compare=&lt;=&amp;meta_value=20&amp;orderby=meta_value&amp;order=DESC&#039;);
</pre>
<div class="incontent">
<h4>Guest Post</h4>
<p>This post is written by Sergej Müller <a href="http://www.wpseo.org">wpseo.org</a> and is a post in our Advent Calendar on WP Engineer about WordPress.<br />
Thank you very much from my part to <a href="http://www.wpseo.org">Sergej</a>.<br />
If you also like to have your interesting post published on our website, please let us know on our contact page. Of course we will appreciate your contribution!
</div>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1915/sort-posts-custom-fields/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

