<?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>Dev4Press&#187; array Tag Archives, page 1 of 1 | Dev4Press</title>
	<atom:link href="http://www.dev4press.com/tag/array/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dev4press.com</link>
	<description>Premium Plugins and Themes for WordPress</description>
	<lastBuildDate>Sun, 26 May 2013 06:04:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Exclude subcategories from RSS feed</title>
		<link>http://www.dev4press.com/2011/tutorials/wordpress/tips/exclude-subcategories-from-rss-feed/</link>
		<comments>http://www.dev4press.com/2011/tutorials/wordpress/tips/exclude-subcategories-from-rss-feed/#comments</comments>
		<pubDate>Sat, 01 Oct 2011 19:15:08 +0000</pubDate>
		<dc:creator>MillaN</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[children categories]]></category>
		<category><![CDATA[extra parameters]]></category>
		<category><![CDATA[main categories]]></category>
		<category><![CDATA[parameters]]></category>
		<category><![CDATA[query methods]]></category>
		<category><![CDATA[query posts]]></category>
		<category><![CDATA[query variable]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[sub categories]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.dev4press.com/?p=9672</guid>
		<description><![CDATA[WordPress WP_Query class is used to get posts for, basically, everything. And this class is very, very complicated. It has a long list of supported query variables, filters and actions to control the process. But, even with all that, there are some limitations in conventional methods of use.]]></description>
				<content:encoded><![CDATA[<p>WordPress WP_Query class is used to get posts for, basically, everything. And this class is very, very complicated. It has a long list of supported query variables, filters and actions to control the process. But, even with all that, there are some limitations in conventional methods of use.</p>
<p>If you want to exclude posts that belong to more than one category, you can use query variable called <strong>category__not_in</strong>. You need to specify array with category ID&#8217;s to exclude. But, if you want to exclude sub categories of the categories you have listed, this will no do. To exclude sub categories also, there is a little piece of code you can use. This is very useful for RSS feeds, since you can have better control over posts available in the feed.</p>
<p>First, here is normal example where we want to exclude posts from 4 different categories. First piece of code is classic example to get posts:</p>
<pre class="brush: php; title: ; notranslate">$args = array(&quot;category__not_in&quot; =&gt; array(2, 7, 43, 66));
$posts = get_posts($args);</pre>
<p>And the other one is to do this with RSS feed:</p>
<pre class="brush: php; title: ; notranslate">add_filter(&quot;pre_get_posts&quot;, array(&amp;$this, &quot;d4p_rss_query&quot;));
function d4p_rss_query($query) {
  if ($query-&gt;is_feed) {
    $cats = array(2, 7, 43, 66);
    $query-&gt;set(&quot;category__not_in&quot;, $cats);
  }
  return $query;
}</pre>
<p>But, if these 4 categories have subcategories, than you have a problem, posts in the sub categories will still be in the results. Here is the simple code to change that.</p>
<pre class="brush: php; title: ; notranslate">$cats = array(2, 7, 43, 66);
$main_cats = array(2, 7, 43, 66);
foreach ($main_cats as $cat) {
  $cats = array_merge($cats, get_term_children($cat, &quot;category&quot;));
}
$args = array(&quot;category__not_in&quot; =&gt; $cats);
$posts = get_posts($args);</pre>
<p>First and second line both contain same list of categories. This is to make sure that main categories are also included, and that we can go through the list to get children categories in lines 3 to 5. Again, here is the code for RSS feed.</p>
<pre class="brush: php; title: ; notranslate">add_filter(&quot;pre_get_posts&quot;, array(&amp;$this, &quot;d4p_rss_query&quot;));
function d4p_rss_query($query) {
  if ($query-&gt;is_feed) {
    $cats = array(2, 7, 43, 66);
    $main_cats = array(2, 7, 43, 66);
    foreach ($main_cats as $cat) {
      $cats = array_merge($cats, get_term_children($cat, &quot;category&quot;));
    }
    $query-&gt;set(&quot;category__not_in&quot;, $cats);
  }
  return $query;
}</pre>
<p>You can modify <strong>$args</strong> further with extra parameters, or you can use it with query_posts() function or other query methods. This same methods is used here on Dev4Press to control RSS feeds.</p>
<script src="http://feeds.feedburner.com/~s/adsense@gdragon.info?i=http://www.dev4press.com/2011/tutorials/wordpress/tips/exclude-subcategories-from-rss-feed/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://www.dev4press.com/2011/tutorials/wordpress/tips/exclude-subcategories-from-rss-feed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GD Custom Posts And Taxonomies Tools 3.0.3</title>
		<link>http://www.dev4press.com/2011/blog/plugins-news/gd-custom-posts-and-taxonomies-tools-3-0-3/</link>
		<comments>http://www.dev4press.com/2011/blog/plugins-news/gd-custom-posts-and-taxonomies-tools-3-0-3/#comments</comments>
		<pubDate>Sat, 11 Jun 2011 21:50:20 +0000</pubDate>
		<dc:creator>MillaN</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[bug fixes]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[content type]]></category>
		<category><![CDATA[custom boxes]]></category>
		<category><![CDATA[custom posts]]></category>
		<category><![CDATA[default location]]></category>
		<category><![CDATA[improvements]]></category>
		<category><![CDATA[labels]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[minor bug]]></category>
		<category><![CDATA[predefined functions]]></category>
		<category><![CDATA[registration procedure]]></category>
		<category><![CDATA[registrations]]></category>
		<category><![CDATA[taxonomies]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.dev4press.com/?p=5911</guid>
		<description><![CDATA[New minor revision of GD Custom Posts And Taxonomies Tools is here with few more bug fixes and some improvements for custom fields and custom meta boxes handling. Also, I am pleased to report and now everything in the plugin works as expected with upcoming WordPress 3.2.]]></description>
				<content:encoded><![CDATA[<p>New minor revision of GD Custom Posts And Taxonomies Tools is here with few more bug fixes and some improvements for custom fields and custom meta boxes handling. Also, I am pleased to report and now everything in the plugin works as expected with upcoming WordPress 3.2.</p>
<p>Bug fixes include minor problem with auto generating one of the labels for custom post type (Parent item with colon), it was using plural instead of singular label. You might wanna fix that with your post types. Taxonomy registration procedure had a minor bug with non cached registrations, now fixed. Registered meta boxes were not properly displayed on the post type panel.</p>
<p>As for updates, custom field shortcode has a new filter that can be used to change the output for the custom field value. A function is also added as alternative to WordPress default get_post_meta that uses shortcode method to get value. As for the meta box, you can select default location where to display meta box on the post editor page. And custom field has a new content type: select box that gets data from predefined functions. You can register functions for this field. Function needs to return array with keys and values, and they will be displayed as a choice. Tutorial on this is coming tomorrow.</p>
<p>If you find more bugs with this version, please leave comment or post in forum, and it will be fixed as soon as possible.</p>
<p><strong>More about GD Custom Posts And Taxonomies Tools</strong>:</p>
<blockquote><p><a href="http://d4p.me/gdtt ">http://d4p.me/gdtt </a></p></blockquote>
<script src="http://feeds.feedburner.com/~s/adsense@gdragon.info?i=http://www.dev4press.com/2011/blog/plugins-news/gd-custom-posts-and-taxonomies-tools-3-0-3/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://www.dev4press.com/2011/blog/plugins-news/gd-custom-posts-and-taxonomies-tools-3-0-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Improve your WordPress website speed, Part 2.</title>
		<link>http://www.dev4press.com/2011/tutorials/wordpress/practical/improve-your-wordpress-website-speed-part-2/</link>
		<comments>http://www.dev4press.com/2011/tutorials/wordpress/practical/improve-your-wordpress-website-speed-part-2/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 12:00:57 +0000</pubDate>
		<dc:creator>MillaN</dc:creator>
				<category><![CDATA[Practical]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[cached data]]></category>
		<category><![CDATA[comple]]></category>
		<category><![CDATA[database table]]></category>
		<category><![CDATA[element]]></category>
		<category><![CDATA[elements]]></category>
		<category><![CDATA[menus]]></category>
		<category><![CDATA[new ways]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[page don]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[sql queries]]></category>
		<category><![CDATA[table structure]]></category>
		<category><![CDATA[time speed]]></category>
		<category><![CDATA[transient]]></category>
		<category><![CDATA[transient records]]></category>
		<category><![CDATA[widgets]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.dev4press.com/?p=4796</guid>
		<description><![CDATA[No matter how your website may be fast, it's always good idea to find some new ways to speed it up. This time, speed will be gain by using very simple cache method that will allow you to cache some parts of the page: menus, widgets and other elements that don't change that often.]]></description>
				<content:encoded><![CDATA[<p>No matter how your website may be fast, it&#8217;s always good idea to find some new ways to speed it up. This time, speed will be gain by using very simple cache method that will allow you to cache some parts of the page: menus, widgets and other elements that don&#8217;t change that often.</p>
<h3>Intro</h3>
<p>Many parts of the page don&#8217;t change often, but require many SQL queries to be executed. If you have complex menu that combines categories, pages or posts and it can take more than 20 or even 50 SQL queries to make. For instance, all 3 menus on Dev4Press take about 30 SQL queries to get URL&#8217;s or structure. Similar situation is with widgets that don&#8217;t change every day, but can take a lot of SQL queries.</p>
<p>Cache method that I want to describe uses database to manually store rendered HTML into the wp_options table using transient records that can have expiry time, allowing you to set how long the cached data will be valid. In multisite mode, for rendering that is related to all websites you can use wp_sitemeta table with transient records. I will note the different functions for this later.</p>
<h3>Cache Functions</h3>
<p>We need 2 functions, one to store and other to get data from cache. You can store: objects, arrays, rendered HTML, anything really.</p>
<pre class="brush: php; title: ; notranslate">function dev4press_get_cached_data($name) {
  return get_transient($name);
}
function dev4press_set_cached_data($name, $value, $ttl = 43200) {
 set_transient($name, $value, $ttl);
}</pre>
<ul>
<li><strong>$name</strong>: name for cached object, this needs to be max 45 characters in length due to the limit of database table structure.</li>
<li><strong>$value</strong>: object/array/string to store.</li>
<li><strong>$ttl</strong>: time-to-live, how long the cached value will be valid, in seconds</li>
</ul>
<p>$name must be unique for the element you are storing. After the $ttl time expires, stored element will be invalidated. Also, functions up there are very basic, but they allow you to expand with calculating stats about the hits or misses, or whatever you might need.</p>
<p>Best way to use this cache is for caching complex operations that require more than couple of SQL queries or uses one or more very complex SQL queries. Transient cache requires 2 simple SELECT queries that are very fast. You can always measure operations to determine if the cache will give you performance boost or not.</p>
<h3>Example: WP Menu Cache</h3>
<p>Here is the example how to use this cache method for WordPress menu. WP theme to display menu is <strong>wp_nav_menu()</strong>. So, if you have menu named &#8220;my_menu&#8221;, it&#8217;s usually added to theme like this:</p>
<pre class="brush: php; title: ; notranslate">wp_nav_menu(array(&quot;menu&quot; =&gt; &quot;my_menu&quot;));</pre>
<p>To use cache, code will change to this:</p>
<pre class="brush: php; title: ; notranslate">$menu = dev4press_get_cached_data(&quot;cached_my_menu&quot;);
if ($menu === false) {
  $menu = wp_nav_menu(array(&quot;echo&quot; =&gt; false,&quot;menu&quot; =&gt; &quot;my_menu&quot;));
  dev4press_set_cached_data(&quot;cached_my_menu&quot;, $menu, 86400);
}
echo $menu;</pre>
<p>Line 1 attempts to get stored menu from transient cache by key &#8220;cached_my_menu&#8221;. If the result is false, than we build the menu as before (using echo parameter set to false, so that menu is not displayed) on line 3. And when the menu is built, we need to store rendered HTML to transient cache using same &#8221;cached_my_menu&#8221; key on line 4. And than display menu on last line.</p>
<p>First time the menu needs to be displayed, cache will be empty, and lines 3 and 4 will execute making menu and caching it. Next time, line 1 will get the menu from cache skipping rebuild part. After 24 hours (86400), menu will be invalidated, and first line will again return false, and menu will be rebuilt again.</p>
<p>Same principle can be used to handle any type of data to cache.</p>
<h3>gdr2 Library</h3>
<p>My gdr2 Library used in all my premium plugins and themes has own Cache class that is based on this method. Cache class supports statistics, unique name building and other things. It&#8217;s used to cache widgets in plugins and to cache widgets and menus in xScape themes. On Dev4Press website, powered by <a title="lightScape" href="http://www.dev4press.com/themes/lightscape/">lightScape</a> theme, widgets are cached and also main menu and the footer links map. Top menu items depend on the user, so it&#8217;s not the same for everyone, and caching it is not good idea.</p>
<h3>Conclusion</h3>
<p>I will search further for more things you can do to optimize websites, so more posts like this will be added. If you have some more suggestions on WordPress speed improving, please leave a comment.</p>
<script src="http://feeds.feedburner.com/~s/adsense@gdragon.info?i=http://www.dev4press.com/2011/tutorials/wordpress/practical/improve-your-wordpress-website-speed-part-2/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://www.dev4press.com/2011/tutorials/wordpress/practical/improve-your-wordpress-website-speed-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Get posts for a category</title>
		<link>http://www.dev4press.com/2010/tutorials/wordpress/tips/get-posts-for-a-category/</link>
		<comments>http://www.dev4press.com/2010/tutorials/wordpress/tips/get-posts-for-a-category/#comments</comments>
		<pubDate>Sat, 25 Sep 2010 10:57:08 +0000</pubDate>
		<dc:creator>MillaN</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[arguments]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[categories]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[exclude]]></category>
		<category><![CDATA[exclude child categories]]></category>
		<category><![CDATA[posts]]></category>
		<category><![CDATA[settings]]></category>

		<guid isPermaLink="false">http://www.dev4press.com/?p=3254</guid>
		<description><![CDATA[This is basic operation in WordPress, but it's not as straightforward as you might think. For that, you will usually use get_posts() function that allows you to set category, but this function can use many more options than actually documented, you can use all WP Query arguments with it.]]></description>
				<content:encoded><![CDATA[<p>This is basic operation in WordPress, but it&#8217;s not as straightforward as you might think. For that, you will usually use get_posts() function that allows you to set category, but this function can use many more options than actually documented, you can use all WP Query arguments with it.</p>
<p>We will see how to exclude child categories from results and how to do a bit more with some other additional arguments this function can use.</p>
<h3>Basic category settings in get_posts()</h3>
<p>If you follow get_posts() documented arguments, without going any deeper, you will see that you can specify category by ID:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
$posts = get_posts(array('category' =&gt; 1));
?&gt;</pre>
<p>And this will get you 5 posts from specify category and ALL child categories belonging to that one! If you need more than 5 or if you need all, you must set number of posts to get:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
$posts = get_posts(array('numberposts' =&gt; 10000, 'category' =&gt; 1));
?&gt;</pre>
<p>This will get you up to 10.000 posts from category with ID 1 and ALL child categories belonging to it.</p>
<h3>Additional categories arguments</h3>
<p>But, in many cases you don&#8217;t want posts belonging to child categories, you want posts that are specifically assigned to a category. Well, in that case this method is no good. Or is it? Well, you can still use same function, but this time with arguments that were not documented for that function.</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
$posts = get_posts(array('numberposts' =&gt; 10000, 'category__in' =&gt; array(1)));
?&gt;</pre>
<p>Now we are getting somewhere. This will limit results only to category with ID 1, and will ignore any child categories this one might have. You can specify more than one category as a value for<strong> category__in</strong> argument and that will get you posts that belong to at least one of the categories in array.</p>
<p>There are few more arguments that you will find interesting for getting posts in categories.</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
$posts = get_posts(array('category__and' =&gt; array(1, 5, 42)));
$posts = get_posts(array('category__not_in' =&gt; array(3, 71)));
?&gt;</pre>
<p>Line 2 uses <strong>category__and</strong> argument, and this one will get you posts belonging to all specified categories. If a post belongs to 1 and 5 only and not 42 it will not be used. Only posts belonging to 1, 5 and 42 are returned.</p>
<p>Line 3 uses <strong>category__not_in</strong> argument, and this will return posts not belonging to specified categories. In all this cases, you must specify the category ID&#8217;s.</p>
<h3>And more</h3>
<p>For a full list of arguments you can use with get_posts() function, you can check out this article from Codex:<br />
<a href="http://codex.wordpress.org/Function_Reference/query_posts" target="_blank">http://codex.wordpress.org/Function_Reference/query_posts</a></p>
<script src="http://feeds.feedburner.com/~s/adsense@gdragon.info?i=http://www.dev4press.com/2010/tutorials/wordpress/tips/get-posts-for-a-category/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://www.dev4press.com/2010/tutorials/wordpress/tips/get-posts-for-a-category/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk: enhanced
Content Delivery Network via cdn.dev4press.com

 Served from: www.dev4press.com @ 2013-05-26 11:08:34 by W3 Total Cache -->