<?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; WordPress Tutorials</title>
	<atom:link href="http://wpengineer.com/tag/wordpress-tutorials/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>Load Minimum of WordPress</title>
		<link>http://wpengineer.com/2449/load-minimum-of-wordpress/</link>
		<comments>http://wpengineer.com/2449/load-minimum-of-wordpress/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 05:44:39 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2449</guid>
		<description><![CDATA[A small contribution for all those using WordPress as a backend, framework or something similar. The applications, especially in the B2B sector, becoming more and more, as do the questions. So far, I've always liked to recommended BackPress. But even a well-maintained standard is feasible, with all its advantages in the context of the philosophy [...]]]></description>
			<content:encoded><![CDATA[<p>A small contribution for all those using WordPress as a backend, framework or something similar. The applications, especially in the B2B sector, becoming more and more, as do the questions.</p>
<p>So far, I've always liked to recommended <a href="http://backpress.org/">BackPress</a>. But even a well-maintained standard is feasible, with all its advantages in the context of the philosophy of updates. WordPress reduces initializing to a minimum, if the constant <code>SHORTINIT</code> is set.<br />
<span id="more-2449"></span><br />
The <code>wp-settings.php</code> of WordPress is the key.</p>
<pre>
// Stop most of WordPress from being loaded if we just want the basics.
if ( SHORTINIT )
	return false;
</pre>
<p>Thus, the loading process is much slimmer and files that are loaded later, must be integrated via a Plugin or Theme functions. The ability is worth it and not infrequently, the part of WordPress in some projects is so small compared to your own developments, that this is worth to do.</p>
<p>Activating in <code>wp-config.php</code> via <code>define( 'SHORTINIT', TRUE );</code> is done quickly and you can start the test, but note: the globals <code>$wp, $wp_query, $wp_the_query</code> was set as <code>NULL</code>.<br />
<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/2449/load-minimum-of-wordpress/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Adding Custom Fields to WordPress User Profile</title>
		<link>http://wpengineer.com/2173/custom-fields-wordpress-user-profile/</link>
		<comments>http://wpengineer.com/2173/custom-fields-wordpress-user-profile/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 07:08:34 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2173</guid>
		<description><![CDATA[The user profile of WordPress can be fairly easily adapted to add your own values​​. So you can add the necessary fields according to your requirements. Here is how you do it, we add a field for the address and the content will be stored in the database. Various hooks in WordPress make sure that [...]]]></description>
			<content:encoded><![CDATA[<p>The user profile of WordPress can be fairly easily adapted to add your own values​​. So you can add the necessary fields according to your requirements. Here is how you do it, we add a field for the address and the content will be stored in the database. Various hooks in WordPress make sure that you only have to worry about the fields.<br />
<span id="more-2173"></span><br />
<img src="http://wpengineer.com/wp-content/uploads/custom-profile-fields.png" alt="" title="custom-profile-fields" width="630" height="162" class="aligncenter size-full wp-image-2174" /></p>
<p>The function to store the entries is <code>fb_save_custom_user_profile_fields()</code> and here it is important to check the rights of each active user, only if the rights are available, in this case for editing users (<code>edit_user</code>), then data may be stored.<br />
The actual saving of data takes place via <code>update_usermeta()</code>.</p>
<p>It can pass all kinds of fields of course, the input field is just an example. It is advisable to outsource the functions in a Plugin, an alternative is also the <code>functions.php</code> of the Theme, but is certainly not the best way.</p>
<p>Each function of the small sample was referred to two hooks. Because WordPress differentiate between editing of user profiles and update personal data. This is done using the constant <code>IS_PROFILE_PAGE</code>. On default this constant is on TRUE and so would the hooks <code>show_user_profile</code> and <code>personal_options_update</code> be enough to bring in new fields and save them. But this can vary depending on the installation and this way the admin cannot maintain these new fields. In particular, two more hooks are needed. Otherwise there might be many cases, where the admin has to maintain data which the user doesn't even see in his profile.</p>
<pre>
function fb_add_custom_user_profile_fields( $user ) {
?&gt;
	&lt;h3&gt;&lt;?php _e(&#039;Extra Profile Information&#039;, &#039;your_textdomain&#039;); ?&gt;&lt;/h3&gt;

	&lt;table class=&quot;form-table&quot;&gt;
		&lt;tr&gt;
			&lt;th&gt;
				&lt;label for=&quot;address&quot;&gt;&lt;?php _e(&#039;Address&#039;, &#039;your_textdomain&#039;); ?&gt;
			&lt;/label&gt;&lt;/th&gt;
			&lt;td&gt;
				&lt;input type=&quot;text&quot; name=&quot;address&quot; id=&quot;address&quot; value=&quot;&lt;?php echo esc_attr( get_the_author_meta( &#039;address&#039;, $user-&gt;ID ) ); ?&gt;&quot; class=&quot;regular-text&quot; /&gt;&lt;br /&gt;
				&lt;span class=&quot;description&quot;&gt;&lt;?php _e(&#039;Please enter your address.&#039;, &#039;your_textdomain&#039;); ?&gt;&lt;/span&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;
&lt;?php }

function fb_save_custom_user_profile_fields( $user_id ) {

	if ( !current_user_can( &#039;edit_user&#039;, $user_id ) )
		return FALSE;

	update_usermeta( $user_id, &#039;address&#039;, $_POST&#091;&#039;address&#039;&#093; );
}

add_action( &#039;show_user_profile&#039;, &#039;fb_add_custom_user_profile_fields&#039; );
add_action( &#039;edit_user_profile&#039;, &#039;fb_add_custom_user_profile_fields&#039; );

add_action( &#039;personal_options_update&#039;, &#039;fb_save_custom_user_profile_fields&#039; );
add_action( &#039;edit_user_profile_update&#039;, &#039;fb_save_custom_user_profile_fields&#039; );
</pre>
<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/2173/custom-fields-wordpress-user-profile/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Easier Plugin Development by Moving Plugin Directory</title>
		<link>http://wpengineer.com/2374/easier-plugin-development-by-moving-plugin-directory/</link>
		<comments>http://wpengineer.com/2374/easier-plugin-development-by-moving-plugin-directory/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 07:07:50 +0000</pubDate>
		<dc:creator>Latz</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2374</guid>
		<description><![CDATA[If you're a experienced programmer you're testing your programs not only with the latest version of WordPress but also with some older versions since there are many dated installations. So you have several versions installed on your development server and want to test your newly created code with every single version. You could copy your [...]]]></description>
			<content:encoded><![CDATA[<p>If you're a experienced programmer you're testing your programs not only with the latest version of WordPress but also with some older versions since there are <a title="WordPress Infographic" href="http://hackertarget.com/wordpress-infographic/">many dated installations</a>. So you have several versions installed on your development server and want to test your newly created code with every single version.<br />
<span id="more-2374"></span><br />
You could copy your plugin files to all installed version's plugin directory manually every time you change the code... but you're a programmer, so this is no option, is it?<br />
If your dev server works under a *nix system you probably have tried to use symbolic links but it didn't work. This is not a bug of WordPress but <a href="https://bugs.php.net/bug.php?id=46260">of PHP</a>. So this does not work either.</p>
<p>Fortunately WordPress defines two constants which can help you to simplify things nonetheless: <code>WP_PLUGIN_DIR</code> and <code>WP_PLUGIN_URL</code>. These constants point to the plugin directory of the respective WordPress installation. They are defined since WordPress 2.6 and supporting older versions is most likely unnecessary<br />
.<br />
To make your plugins accessible to all your installed WordPress versions you simply move them to a central directory and define the constants accordingly:</p>
<pre lang="php">
define( &#039;WP_PLUGIN_DIR&#039;, &#039;/var/www/plugins&#039; ); // or with XAMPP C:/xampp/htdocs/plugins
define( &#039;WP_PLUGIN_URL&#039;, &#039;http://localhost/plugins&#039; );
</pre>
<p>In this example the plugins reside in the directory 'plugins' in the root directory of the webserver. If you now define the above constants in every WordPress installation you have easy access to them to test your code with every version. </p>
<p>(Thanks to <a href="http://profiles.wordpress.org/users/johnbillion">John Blackbourn</a> on the <a href="http://lists.automattic.com/mailman/listinfo/wp-hackers">wp-hackers</a> list for having the idea.)</p>
<h4>Hint for Multisite-Users</h4>
<p>Also usable for WordPress Multisite</p>
<pre lang="php">
define( &#039;WPMU_PLUGIN_DIR&#039;, &#039;/var/www/multisite-plugins&#039; );
define( &#039;WPMU_PLUGIN_URL&#039;, &#039;http://localhost/multisite-plugins&#039; );
</pre>
<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/2374/easier-plugin-development-by-moving-plugin-directory/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Force Reload of Scripts and Stylesheets in your Plugin or Theme</title>
		<link>http://wpengineer.com/2292/force-reload-of-scripts-and-stylesheets-in-your-plugin-or-theme/</link>
		<comments>http://wpengineer.com/2292/force-reload-of-scripts-and-stylesheets-in-your-plugin-or-theme/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 06:13:38 +0000</pubDate>
		<dc:creator>Latz</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2292</guid>
		<description><![CDATA[If you're developing a WordPress theme or plugin you may have had the problem that scripts or stylesheets are not reloaded from the source when you refresh the page because they are cached somewhere on the way from the server to the browser. There are various methods to suppress this behaviour like disabling the browser [...]]]></description>
			<content:encoded><![CDATA[<p>If you're developing a WordPress theme or plugin you may have had the problem that scripts or stylesheets are not reloaded from the source when you refresh the page because they are cached somewhere on the way from the server to the browser. There are various methods to suppress this behaviour like disabling the browser cache in the options or by using a web development add-on. Sometimes this simply does not work because it's not always apparent where the content is cached since there are so many possibilities and you may have missed to disable all of them.</p>
<p>WordPress provides a simple method to ensure that all stylesheets and scripts are reloaded from the source when they have changed by providing a version parameter:</p>
<pre lang="php">
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
wp_enqueue_style( $handle, $src, $deps, $ver, $media);
</pre>
<p>You can increase the <code>$ver</code> parameter every time you've changed the files:</p>
<pre lang="php">
wp_enqueue_script( &#039;my_script&#039;, &#039;my_script.js&#039;, &#039;&#039;, &#039;0.11&#039; );
wp_enqueue_style( &#039;my_style&#039;, &#039;my_style.css&#039;, &#039;&#039;, &#039;0.11&#039; );
</pre>
<p>The URL of the stylesheet/script will be changed to '<code>.../my_script.js?ver=0.11</code>' so that every caching system detects the changed file and reloads it from its source and the user always gets the recent version.</p>
<p>But to change the version number manually every time in the development stage would be a bit tedious and you're a programmer, right? So let's automate this:</p>
<pre lang="php">
wp_enqueue_script( &#039;my_script&#039;, &#039;my_script.js&#039;, &#039;&#039;, time() );
wp_enqueue_style( &#039;my_style&#039;, &#039;my_style.css&#039;, &#039;&#039;, time() );
</pre>
<p>The value of <a href="http://php.net/manual/de/function.time.php">time()</a> changes every second so the version ID of the file changes constantly and it's reloaded from the source and not from some cache.</p>
<p>It's a bit disadvantageous that you have to substitute the time based version parameter by a "real" version number every time you deploy your code since the actual user still should have the benefits of cached scripts and stylesheets. Let's extend the idea:</p>
<pre lang="php">
define (&#039;VERSION&#039;, &#039;1.1&#039;);

function version_id() {
  if ( WP_DEBUG )
    return time();
  return VERSION;
}

wp_enqueue_script( &#039;my_script&#039;, &#039;my_script.js&#039;, &#039;&#039;, version_id() );
wp_enqueue_style( &#039;my_style&#039;, &#039;my_style.css&#039;, &#039;&#039;, version_id() );
</pre>
<p>This way you can make sure that in your development environment everything is reloaded from source all the time but a productive server takes advantage of caches.</p>
<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/2292/force-reload-of-scripts-and-stylesheets-in-your-plugin-or-theme/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Remove Menu Item in WordPress Admin Panel</title>
		<link>http://wpengineer.com/2233/remove-menu-item-in-wordpress-admin-panel/</link>
		<comments>http://wpengineer.com/2233/remove-menu-item-in-wordpress-admin-panel/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 05:50:40 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp3.1]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2233</guid>
		<description><![CDATA[With WordPress Version 3.1 two new functions were added which makes it easier to remove menu- and submenu-entries in WordPress Admin Panel. These functions removing entries of the menu-tree remove_menu_page or submenus - remove_submenu_page. /** * Remove a top level admin menu * * @param string $menu_slug The slug of the menu * @return array&#124;bool [...]]]></description>
			<content:encoded><![CDATA[<p>With WordPress Version 3.1 two new functions were added which makes it easier to remove menu- and submenu-entries in WordPress Admin Panel. These functions removing entries of the menu-tree <code>remove_menu_page</code> or submenus - <code>remove_submenu_page</code>.<br />
<span id="more-2233"></span></p>
<pre>
/**
 * Remove a top level admin menu
 *
 * @param string $menu_slug The slug of the menu
 * @return array|bool The removed menu on success, False if not found
 */
remove_menu_page( $menu_slug )
</pre>
<pre>
/**
 * Remove an admin submenu
 *
 * @param string $menu_slug The slug for the parent menu
 * @param string $submenu_slug The slug of the submenu
 * @return array|bool The removed submenu on success, False if not found
 */
remove_submenu_page( $menu_slug, $submenu_slug ) {
</pre>
<p>It's easy to remove menu entries and it is not necessary anymore to read the arrays $menu and $submenu. Until now you had to search for them in the array and remove them via unset() from the array. Alternatively you were also able to find the entry on the basis of a key - the above new features make this unnecessary and as a parameter value only the "slug" is passed, which can be found in the link or the URL of the backend. A small example, where we remove the entries to the comments and the submenu-page discussion will show the new possibilities.</p>
<pre>
function fb_remove_menu_entries () {
	// with WP 3.1 and higher
	if ( function_exists( &#039;remove_menu_page&#039; ) ) {
		remove_menu_page( &#039;edit-comments.php&#039; );
		remove_submenu_page( &#039;options-general.php&#039;, &#039;options-discussion.php&#039; );
	} else {
		// unset comments
		unset( $GLOBALS&#091;&#039;menu&#039;&#093;&#091;25&#093; );
		// unset menuentry Discussion
		unset( $GLOBALS&#091;&#039;submenu&#039;&#093;&#091;&#039;options-general.php&#039;&#093;&#091;25&#093; );
	}
}
add_action( &#039;admin_menu&#039;, &#039;fb_remove_menu_entries&#039; );
</pre>
<p>The above code provides a simple solution, removed the two entries and also has a fallback for WordPress, smaller version 3.1. It is also conceivable that the removal is also connected with user rights</p>
<pre>if ( function_exists( &#039;remove_menu_page&#039; ) &amp;&amp; ! current_user_can( &#039;manage_options&#039; ) ) {</pre>
<p>so it would be possible to optimize the menu explicitly for a user.  Alternatively, the plug <a href="http://wordpress.org/extend/plugins/adminimize/">Adminimize</a> helps and facilitates the job via admin area.<br />
You can also read about this topic on <a href="http://devpress.com/blog/removing-menu-pages-from-the-wordpress-admin/">Justin's post</a>, but my post was an older draft and now was published - the topic is worth it.<br />
<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/2233/remove-menu-item-in-wordpress-admin-panel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Publish Your Posts Later On Your Website</title>
		<link>http://wpengineer.com/2235/publish-your-posts-later-on-your-website/</link>
		<comments>http://wpengineer.com/2235/publish-your-posts-later-on-your-website/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 10:37:57 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2235</guid>
		<description><![CDATA[I explained quite a while ago about publishing a feed with a certain delay. Of course you can do this also for your frontend. Thus, the content will be published to the reader only after a certain period of time. A little script as an example will show you how. The function can be expanded, [...]]]></description>
			<content:encoded><![CDATA[<p>I <a title="Publish The Feed Later" href="http://wpengineer.com/320/publish-the-feed-later/">explained</a> quite a while ago about publishing a feed with a certain delay. Of course you can do this also for your frontend. Thus, the content will be published to the reader only after a certain period of time. A little script as an example will show you how.<br />
<span id="more-2235"></span></p>
<p>The function can be expanded, for example, with queries on rights of the logged users or various other requirements.</p>
<p>In the first snippet the output on the frontend is always filtered, only your backend <code>is_admin()</code> and your feed <code>is_feed()</code> keeps untouched. The filter is placed in the example at 15 minutes and these are aligned with the setting of WordPress, so that the time zone will be considered. The 15 minutes will be converted into seconds and subtracted from the value.</p>
<pre>&lt;code&gt;
function publish_later_on_frontend( $where ) {

	if ( is_admin() || is_preview() || is_feed() )
		return $where;

	$offset =  15; // minutes
	$offset = ( get_option( &#039;gmt_offset&#039; ) * 3600 ) - ( $offset * 60 ); // gmt offset of WP options minus custom time
	$where .= &quot; AND post_date &lt; &#039;&quot; . gmdate( &#039;Y-m-d H:i:s&#039;, ( time() + $offset ) ) . &quot;&#039;&quot;;

	return $where;
}
add_filter( &#039;posts_where&#039;, &#039;publish_later_on_frontend&#039; );
&lt;/code&gt;</pre>
<p>Another brief example will allow all users logged, with minimum rights to read  <code>current_user_can('read')</code> - so subscribers, to read the contents. All other visitors will get the content presented 10 days later.</p>
<pre>&lt;code&gt;
function publish_later_on_frontend( $where ) {

	if ( is_admin() || is_preview() || is_feed() || current_user_can(&#039;read&#039;) )
		return $where;

	$offset =  10; // days
	$offset = ( get_option( &#039;gmt_offset&#039; ) * 3600 ) - ( $offset * 24 * 60 * 60 ); // gmt offset of WP options minus custom time
	$where .= &quot; AND post_date &lt; &#039;&quot; . gmdate( &#039;Y-m-d H:i:s&#039;, ( time() + $offset ) ) . &quot;&#039;&quot;;

	return $where;
}
add_filter( &#039;posts_where&#039;, &#039;publish_later_on_frontend&#039; );
&lt;/code&gt;</pre>
<p>Alternatives with SQL-Statement:</p>
<pre>
// with INTERVAL
$where .= &quot; AND post_date &lt; NOW() - INTERVAL 5 MINUTE&quot;; // DAY, HOUR

// with strtotime()
$where .= &quot; AND post_date &lt; FROM_UNIXTIME(&quot; . strtotime(&quot;-5 day&quot;). &quot;)&quot;;
</pre>
<p>Well - any other ideas? Then let us know in our comment area. I'm happy to see any improvements to the code, especially in the area of calculation with time.<br />
<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/2235/publish-your-posts-later-on-your-website/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Adding Input Fields To Comment Form</title>
		<link>http://wpengineer.com/2214/adding-input-fields-to-the-comment-form/</link>
		<comments>http://wpengineer.com/2214/adding-input-fields-to-the-comment-form/#comments</comments>
		<pubDate>Tue, 03 May 2011 09:22:35 +0000</pubDate>
		<dc:creator>Latz</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[comment form]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[template tag]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2214</guid>
		<description><![CDATA[Most comment forms contain the same input fields: Name, Email, URL and the comment text field. This is sufficient for most use cases but there are situations where you might want to know a bit more about your commenter: their age, the city they live in, or the color of their underwear. This article explains [...]]]></description>
			<content:encoded><![CDATA[<p>Most comment forms contain the same input fields: Name, Email, URL and the comment text field. This is sufficient for most use cases but there are situations where you might want to know a bit more about your commenter: their age, the city they live in, or the color of their underwear. This article explains how to add an input field, store the data in the database and how to display the additional data in your blog if your theme uses the <code>comment_form()</code> function provided by WordPress.<span id="more-2214"></span></p>
<h3>Adding the input field</h3>
<p>As an example we will add an input field asking for the city the commenter lives in. Additionally the field will be marked as mandatory.</p>
<p>To add an additional input field you have to modify the comment form defaults by setting a filter for the function <code>comment_form_defaults</code>:</p>
<pre>
add_filter( &#039;comment_form_defaults&#039;, &#039;change_comment_form_defaults&#039;);
</pre>
<p>For adding the new input field after the email field you need to extend the default "Email" input field:</p>
<pre>
function change_comment_form_defaults( $default ) {
    $commenter = wp_get_current_commenter();
    $default&#091; &#039;fields&#039; &#093;&#091; &#039;email&#039; &#093; .= &#039;&lt;p class=&quot;comment-form-author&quot;&gt;&#039; .
        &#039;&lt;label for=&quot;city&quot;&gt;&#039;. __(&#039;City&#039;) . &#039;&lt;/label&gt;
        &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt;
        &lt;input id=&quot;city&quot; name=&quot;city&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;&lt;/p&gt;&#039;;
    return $default;
}
</pre>
<p>Basically this is the same markup used to create the author field with modified values for <code>label</code>, <code>name</code>, and <code>id</code> and "<code>&lt;span class="required"&gt;*&lt;/span&gt;"</code> added to mark the field as mandatory (only visually).</p>
<h3>Storing the data in the database</h3>
<p>Storing the value of the new field is quite simple since WordPress already contains a table in the database called <code>commentmeta</code> for storing exactly this type of data called meta data.<br />
The usage of this table is straightforward since WordPress provides the two functions <code>add_comment_meta()</code> and <code>get_comment_meta()</code>:</p>
<pre>
add_comment_meta($comment_id, $meta_key, $meta_value, $unique = false)
get_comment_meta( $comment_id, $meta_key, $single = false )
</pre>
<p>To store the meta data together with the other comment data an action needs to be added:</p>
<pre>
add_action( &#039;comment_post&#039;, &#039;save_comment_meta_data&#039; );

function save_comment_meta_data( $comment_id ) {
    add_comment_meta( $comment_id, &#039;city&#039;, $_POST&#091; &#039;city&#039; &#093; );
}
</pre>
<p>To make the city field mandatory the script needs to check if the user had entered some text before the data is stored. WordPress provides a filter named <code>preprocess_comment</code> which can be used to verify the data:</p>
<pre>
add_filter( &#039;preprocess_comment&#039;, &#039;verify_comment_meta_data&#039; );

function verify_comment_meta_data( $commentdata ) {
    if ( ! isset( $_POST&#091;&#039;city&#039;&#093; ) )
        wp_die( __( &#039;Error: please fill the required field (city).&#039; ) );
    return $commentdata;
}
</pre>
<p>The data is not actually processed but it is tested if the field <code>$_POST['city']</code> contains any data. If there is no data the script will die with an error message otherwise the comment data will be returned unaltered.<br />
Alternative ist the Action Hook <code>pre_comment_on_post</code> usable.</p>
<h3>Retrieving and displaying the data</h3>
<p>To retrieve the data from the database WordPress provides the function <code>get_comment_meta</code>. To avoid to modify the theme template the city name is attached to the author name by using the filter <code>get_comment_author_link</code>:</p>
<pre>
add_filter( &#039;get_comment_author_link&#039;, &#039;attach_city_to_author&#039; );

function attach_city_to_author( $author ) {
    $city = get_comment_meta( get_comment_ID(), &#039;city&#039;, true );
    if ( $city )
        $author .= &quot; ($city)&quot;;
    return $author;
}
</pre>
<h3>Advanced usage</h3>
<p>You might have noticed that both functions <code>add_comment_meta()</code> and <code>get_comment_meta()</code> contain parameters that haven't been explained yet, namely <code>$unique</code> and <code>$single</code>.</p>
<p>The <code>$unique</code> parameter controls whether you can add multiple data field with the same key name for the same comment_id. But why would you want do such a thing?<br />
Let's assume you want to allow the user to add multiple cities separated by commas. Surely you can store the whole string in a single table row but that would make the data hard to handle if you want to use it in a different context and it simply conflicts with basic database principles. So the input data will be split and each city is stored in its own dataset:</p>
<pre>
function save_comment_meta_data( $comment_id ) {
    $cities = explode( &#039;,&#039;, $_POST&#091; &#039;city&#039; &#093; );
    foreach ( $cities as $city )
       echo add_comment_meta( $comment_id, &#039;city&#039;, $city, false );
}
</pre>
<p>If the user enters e.g. three city names all three are stored with the keyname <code>city</code>. If the parameter <code>unique</code> would have been set to <code>true</code> only the first city would have been stored because the parameter prevents the storage attempts of the last two city names.</p>
<p>When retrieving the data with <code>get_comment_meta</code> the parameter <code>$single</code> comes into view. If it is set to <code>false</code> the function does not return a single value but an array of values.</p>
<pre>
function attach_city_to_author( $author ) {
    $cities = get_comment_meta( get_comment_ID(), &#039;city&#039;, false );
    if ( $cities ) {
        $author .= &#039; ( &#039;;
        foreach ( $cities as $city )
            $author .= $city . &#039; &#039;;
        $author .= &#039;)&#039;;
    }
    return $author;
}
</pre>
<h3>Modifying the meta data</h3>
<p>There might be situations where you want to change the meta data stored in the database. As expected WordPress provides a function for this called <code>update_comment_meta()</code>:</p>
<pre>
update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value );
</pre>
<p>To modify a value you use the function the same way you use <code>add_comment_meta</code>:</p>
<pre>
$new_city = &quot;Timbuktu&quot;;
update_comment_meta( $comment_id, &#039;city&#039;, $new_city );
</pre>
<p>If the <code>$meta_key</code> does not exist the function adds the meta data to the database. But what is the parameter <code>$prev_value</code> used for?<br />
As noticed above you can store more than one value with the same meta key for a single comment. The code snippet above would change all values with the key 'city'. If you set the parameter <code>$prev_value</code> to the value that is to be modified the function will do exactly what is intended:</p>
<pre>
$old_city = &quot;Berlin&quot;;
$new_city = &quot;Timbuktu&quot;;
update_comment_meta( $comment_id, &#039;city&#039;, $new_city, $old_city );
</pre>
<h3>Behind the scenes</h3>
<p>The structure of the commentmeta table is quite simple:</p>
<table align="center">
<tr>
<th>meta_id</th>
<th>comment_id</th>
<th>meta_key</th>
<th>meta_value</th>
</tr>
<tr>
<td>bigint(20)</td>
<td>bigint(20)</td>
<td>varchar(255)</td>
<td>longtext</td>
</tr>
</table>
<p>The <code>meta_id</code> is an auto-incremented ID and <code>comment_id</code> is of course the ID of the comment. The actual data is stored in the <code>meta_key</code> and <code>meta_value</code> fields, containing the keyname (in our case 'city') and the actual value (the name of the city the user entered). Example:</p>
<table>
<tr>
<th>meta_id</th>
<th>comment_id</th>
<th>meta_key</th>
<th>meta_value</th>
</tr>
<tr>
<td>45</td>
<td>76</td>
<td>city</td>
<td>Berlin</td>
</tr>
<tr>
<td>46</td>
<td>77</td>
<td>city</td>
<td>Hamburg</td>
</tr>
<tr>
<td>47</td>
<td>78</td>
<td>city</td>
<td>Hamburg</td>
</tr>
<tr>
<td>48</td>
<td>78</td>
<td>city</td>
<td>Berlin</td>
</tr>
<tr>
<td>49</td>
<td>78</td>
<td>city</td>
<td>Mainz</td>
</tr>
</table>
<p>The comments with the ID 76 and 77 contain meta data with only one value assigned to the key 'city' whereas the comment with the ID 78 got three different values with the same key.</p>
<h3>Look it up</h3>
<p>If you want to look up the {add|get|update}_meta_data functions in the core you can find them in <code>.../wp-includes/comment.php</code>.<br />
The default values of the comment form which are modified above are defined in <code>../wp-includes/comment-form.php</code> in the function <code>comment_form()</code>.</p>
<h3>Source code</h3>
<p>Download the complete sources of the examples above:</p>
<ul>
<li>via Gist: <a href="https://gist.github.com/953193">Single value meta data</a></li>
<li>via Gist: <a href="https://gist.github.com/953195">Multi value meta data</a></li>
</ul>
<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/2214/adding-input-fields-to-the-comment-form/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Comment Form Hooks Visualized</title>
		<link>http://wpengineer.com/2205/comment-form-hooks-visualized/</link>
		<comments>http://wpengineer.com/2205/comment-form-hooks-visualized/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 09:59:55 +0000</pubDate>
		<dc:creator>Latz</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[comment form]]></category>
		<category><![CDATA[comment hooks]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[template_tag]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2205</guid>
		<description><![CDATA[Most themes (e.g. TwentyTen) use the comment_form() function to insert the comment form after posts. There are quite some hooks inside the function but they are hard to localize. The codex documentation isn't too helpful, neither. To give you an easy overview the following diagrams visualize the points where the various hooks are anchored. The [...]]]></description>
			<content:encoded><![CDATA[<p>Most themes (e.g. TwentyTen) use the <code>comment_form()</code> function to insert the comment form after posts. There are quite some hooks inside the function but they are hard to localize. The <a href="https://codex.wordpress.org/Plugin_API/Action_Reference#Comment.2C_Ping.2C_and_Trackback_Actions">codex documentation</a> isn't too helpful, neither.<br />
To give you an easy overview the following diagrams visualize the points where the various hooks are anchored. The number of available hooks depend on the <a href="https://codex.wordpress.org/Settings_Discussion_SubPanel">discussion settings</a> and the <a href="https://codex.wordpress.org/Roles_and_Capabilities">user's capabilities</a>.</p>
<p>In the most common scenario the user is not logged in, is allowed to comment on the article and the comments are not closed:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/default-wpe.png" alt="" title="default-wpe" width="560" height="453" class="aligncenter size-full wp-image-2208" /></p>
<p>There are six hooks available:</p>
<ul>
<li>comment_form_before</li>
<li>comment_form_top</li>
<li>comment_form_before_fields</li>
<li>comment_form_after_fields</li>
<li>comment_form</li>
<li>comment_form_after</li>
</ul>
<p>You might have noticed that the hooks <code>comment_form</code> and <code>comment_form_after</code> seem to be anchored almost at the same point but depending on the user's role and discussion settings they are not always available so you should take care which hook you are using in your code.</p>
<p><br/><strong><u>User logged in</u></strong><br />
If you are logged in you have fewer hooks available since the name, email and URL input fields are not needed. The missing hooks are</p>
<ul>
<li>form_comment_before_fields</li>
<li>form_comment_after fields</li>
</ul>
<p><img src="http://wpengineer.com/wp-content/uploads/logged_in_wpe.png" alt="" title="logged_in_wpe" width="560" height="296" class="aligncenter size-full wp-image-2209" /></p>
<p><br/><u><strong>User is not logged and "Users must be registered and logged in to comment" activated</strong></u><br />
If your blog is configured that only registered users can comment, an unregistered user will see this comment form and additionally the hook <code>comment_form_must_log_in_after</code> is available. Please notice that in this case the hook <code>comment_form</code> is left out.<br />
<img src="http://wpengineer.com/wp-content/uploads/must_log_in-wpe.png" alt="" title="must_log_in-wpe" width="560" height="136" class="aligncenter size-full wp-image-2212" /></p>
<p><br/>
<p><strong><u>Comments closed</u></strong><br />
If the comments on the post are closed you have only one hook left (<code>comment_form_closed</code>) since the form is not displayed at all:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/comments_closed-wpe.png" alt="" title="comments_closed-wpe" width="560" height="59" class="aligncenter size-full wp-image-2213" /></p>
<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/2205/comment-form-hooks-visualized/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>php-Console with Chrome and WordPress</title>
		<link>http://wpengineer.com/2197/php-console-with-chrome-and-wordpress/</link>
		<comments>http://wpengineer.com/2197/php-console-with-chrome-and-wordpress/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 09:46:43 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2197</guid>
		<description><![CDATA[Google Browser Chrome and their Chromium project are becoming more popular. Initially it was the speed of Chrome, which made it so popular but now also the extensions are getting in the focus of the users. Nowadays the extension market of Chrome is full of very useful extensions. Of course there are also many enhancements [...]]]></description>
			<content:encoded><![CDATA[<p>Google Browser <a href="http://www.google.com/chrome">Chrome</a> and their <a href="http://www.chromium.org/Home">Chromium</a> project are becoming more popular. Initially it was the speed of Chrome, which made it so popular but now also the extensions are getting in the focus of the users. Nowadays the extension market of Chrome is full of very useful extensions.  Of course there are also many enhancements in the context of web development that have helped <a href="http://www.mozilla-europe.org">Firefox</a> to fame.</p>
<p>In the field of PHP development, I've always looked at several solutions, played with different options and in the end I'm sitting in front of a browser with IDE, XDebug or some of my own extensions. In Firefox I have used FirePHP in various areas, more information about it can be found in <a href="http://wpengineer.com/1219/firephp-and-wordpress/">this article</a>. Alternatively I also wrote about the <a href="http://wpengineer.com/2068/debugconsole-with-wordpress/">debugConsole</a>. Therefore it was natural to browse for a solution in the environment of Chromium. You will be able to find some interesting topics about it and I would like to introduce <a href="http://code.google.com/p/php-console/">php-console</a> and show how to integrate it in WordPress via Plugin.<br />
<span id="more-2197"></span></p>
<blockquote><p>PHP Console is extension for Lagger and class PhpConsole, that displays PHP errors/debug messages in Google Chrome console and in notification popups.</p></blockquote>
<p>This statement says it all, after integration of the class you can see nice results. Via Plugin I solved to include the class, which can also included manually at the required spot of the relevant files.</p>
<p>You can check out all the features of the extension <a href="http://code.google.com/p/php-console/">at the project site</a>, documentation and download are also available on the project site.</p>
<p>Here are some insights of the output and maybe it makes you want to test it or even more.</p>
<p>In the first screenshot you see the ouput of the PHP errors, which are shown in the console. You can also get the results after loading the page as a popup, see last screenshot. Therefore are settings of the extension via context menu available.<br />
<a href="http://wpengineer.com/wp-content/uploads/php-console-wp.png"><img src="http://wpengineer.com/wp-content/uploads/php-console-wp-300x247.png" alt="" title="php-console-wp" width="300" height="247" class="aligncenter size-medium wp-image-2199" /></a></p>
<p>Alternatively an output in log, which I created explicitly as an example via Plugin. So it makes it possible to control the output.<br />
<a href="http://wpengineer.com/wp-content/uploads/php-console-wp-log.png"><img src="http://wpengineer.com/wp-content/uploads/php-console-wp-log-300x60.png" alt="" title="php-console-wp-log" width="300" height="60" class="aligncenter size-medium wp-image-2198" /></a></p>
<p>In the last screenshot a complete overview, including a popup - you have a nice overview of all PHP messages so you won't forget anyhting while developing.<br />
<a href="http://wpengineer.com/wp-content/uploads/php-console-wp-frontend1.png"><img src="http://wpengineer.com/wp-content/uploads/php-console-wp-frontend1-300x180.png" alt="" title="php-console-wp-frontend" width="300" height="180" class="aligncenter size-medium wp-image-2201" /></a></p>
<p>Here is my little Plugin (<a href="https://github.com/bueltge/php-Console-for-WordPress">alternatively at Github</a> for download including all files and folders), whereas I put the class <code>PhpConsole.php</code> of the php-Console in the folder <code>inc</code>. The output in log of the console will be controlled via the function <code>debug()</code>; It is possible to provide a name so you can read the analysis easier. This Plugin is also compatible to my <a href="http://www.webhostgear.com/php-hosting.php">php web hosting</a>, if you'll ask.</p>
<pre>
&lt;?php
/*
Plugin Name: php-console
Plugin URI: http://bueltge.de/
Text Domain: php-console
Domain Path: /languages
Description: &lt;a href=&quot;http://code.google.com/p/php-console/&quot;&gt;php-console&lt;/a&gt; - Google Chrome extension for displaying PHP errors/exceptions/debug messages in browser console or notification popups
Author: Frank B&uuml;ltge
Version: 0.0.1
Author URI: http://bueltge.de/
Donate URI: http://bueltge.de/wunschliste/
License: GNU v3
Last change: 29.03.2011
*/ 

/* load php-console functionality */
require_once(&#039;inc/PhpConsole.php&#039;);
PhpConsole::start( TRUE, TRUE, dirname(__FILE__) );

class Wp_Php_Console {

	public function __construct() {

		$this-&gt;messages();

		$this-&gt;get_contents( &#039;GNU GENERAL PUBLIC LICENSE&#039; );
	}

	public function messages() {
		global $wpdb, $pagenow;

		debug( $pagenow, &#039;Var Pagenow&#039; );
		$sql = &quot;SELECT * FROM $wpdb-&gt;options&quot;;
		debug( $sql, &#039;sql-options&#039; );
	}

	public function get_contents( $string ) {

		$content = file_get_contents( &#039;../license.txt&#039;, NULL, NULL, 0, 100 );
		$pos = strpos( $content, $string );

		debug( $pos , &#039;Position&#039; );
		if ( ! $pos )
			debug( $content, &#039;Content&#039; );
	}
}
new Wp_Php_Console();

?&gt;
</pre>
<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/2197/php-console-with-chrome-and-wordpress/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Exclude Posts and Pages in WordPress Search</title>
		<link>http://wpengineer.com/2176/exclude-posts-and-pages-in-wordpress-search/</link>
		<comments>http://wpengineer.com/2176/exclude-posts-and-pages-in-wordpress-search/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 10:57:51 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2176</guid>
		<description><![CDATA[Sometimes you don't like to display every post and page on search results. Today I like to show you how to filter the search in your frontend. Therefore I add a filter to the query of WordPress and exclude the according posts or pages of the search. We exclude posts and pages by their ID, [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you don't like to display every post and page on search results. Today I like to show you how to filter the search in your frontend. Therefore I add a filter to the query of WordPress and exclude the according posts or pages of the search.<br />
<span id="more-2176"></span><br />
We exclude posts and pages by their ID, which we will give to an array and so exclude several posts and pages.</p>
<p>In our first code example the IDs are set in the array. The filter is only working if it is the search <em>is_search</em> and if you are not ! in the backend <em>is_admin</em>.</p>
<pre>
// search filter
function fb_search_filter($query) {

    if ( !$query-&gt;is_admin &amp;&amp; $query-&gt;is_search) {
        $query-&gt;set(&#039;post__not_in&#039;, array(40, 9) ); // id of page or post
    }

    return $query;
}
add_filter( &#039;pre_get_posts&#039;, &#039;fb_search_filter&#039; );
</pre>
<p>If you like to exclude the subpage of a page, then you can add it to the ID.</p>
<pre>
// search filter
function fb_search_filter($query) {

    if ( !$query-&gt;is_admin &amp;&amp; $query-&gt;is_search) {
        $pages = array(2, 40, 9); // id of page or post
        // find children to id
        foreach( $pages as $page ) {
            $childrens = get_pages( array(&#039;child_of&#039; =&gt; $page, &#039;echo&#039; =&gt; 0) );
        }
        // add id to array
        for($i = 0; $i &lt; sizeof($childrens); ++$i) {
            $pages&#091;&#093; = $childrens&#091;$i&#093;-&gt;ID;
        }
        $query-&gt;set(&#039;post__not_in&#039;, $pages );
    }

    return $query;
}
add_filter( &#039;pre_get_posts&#039;, &#039;fb_search_filter&#039; );
</pre>
<p>There are many possibilities and I hope I was able to give you a starting point if you like to exclude posts and pages in your search.<br />
<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/2176/exclude-posts-and-pages-in-wordpress-search/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

