Very short trick: Wordpress, reset query

Wednesday, September 9, 2009

To me it happens very often to customize the Home Page index.php or other sections such as the Sidebar, a Web site built with Wordpress. Many of the customizations concern loop with specific parameters in order to see for example the last items of a specific category or tag. This operation, the place almost always using the query_posts() When you run a query_posts() are also affected some global variables, and often annoying when you have behavior - once - using features such as is_category() or is_page() From Release 2.3.0 of WordPress is available a convenient feature that is precisely the task of resetting the state altered by query_posts() wp_reset_query()
You just call the office at the end of our custom loop, so as to leave no trace in the system and so influence other functions that refer to global variables used by query_posts()

PHP:
  1. / / Example in a hypothetical index.php
  2. / / To bottom, after performing one or more
  3. / / Query_posts () Personal
  4. ; get_sidebar ( ) ; get_footer ( ) ; ?> <? php wp_reset_query (); get_sidebar (); get_footer ();?>

Related Post

Was this article helpful?: Per nientePocoAbbastanzaMoltoMoltissimo
Loading ... Loading ...

One comment to "Very short trick: Wordpress, reset a query"

  1. getAvatar 1.0
    05 gen, 2010 Francis

    I was really very auito your post. :-) thanks

Leave a comment

TAG XHTML PERMISSIONS: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre>         // blocco generico [code][/code]       // blocco generico [as][/as]           // Actionscript [css][/css]         // CSS Style Sheet [html][/html]       // HTML [js][/js]           // Javascript [objc][/objc]       // Objective-C [php][/php]         // PHP [sql][/sql]         // SQL