WordPress Reserved Global Variables, You Should Avoid Define A Variable Using These Name
Global variable is a variable that is accessible in every scope, in PHP it works ONLY for the same page and the file that are included after. However, some predefined variables, known as superglobals are always accessible in whole site. Both of global and superglobal variable can be redefined or overwrite it’s value.
When developing a WordPress Plugin and or Theme, sometimes you use the PHP global variable. That’s okay, but it’s HIGHLY RECOMMENDED that you not use variable name that are already defined by WordPress. Why? Because it may break your other code that may intended to use WordPress variable.
Example
Example case:
1. You have this code somewhere in your theme:
$cat = 5; /*define cat global variable */
$paged = 2; /*define paged global variable */
/* Those variable are intended to this custom query */
query_posts("cat=$cat&posts_per_page=10&paged=$paged");
if (have_posts()) while (have_posts()) : the_post();
echo get_the_title().'<br />';
endwhile;
The result is you will get the list of 10 post title from category 5, paged 2. That way as what you expected.
2. On the other hand, you (or other developer) also have this code:
1 2 3 4 |
query_posts("cat=$cat&posts_per_page=10&paged=$paged"); if (have_posts()) while (have_posts()) : the_post(); echo get_the_title().'<br />'; endwhile; |
query_posts("cat=$cat&posts_per_page=10&paged=$paged");
if (have_posts()) while (have_posts()) : the_post();
echo get_the_title().'<br />';
endwhile;
So, do not redefine a reserved WordPress global variable unless you are know what are you doing.
The lists of WordPress Reserved Variable
Anyway, what is the variables that reserved WordPress? Here is the list, the left side is variable name, and the right side is the type:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
$_template_file = string $require_once = boolean $posts = array $post = object $wp_did_header = boolean $wp_did_template_redirect = NULL $wp_query = object $wp_rewrite = object $wpdb = object $wp_version = string $wp = object $id = integer $comment = NULL $user_ID = integer $cat = string $paged = integer $error = string $m = integer $p = integer $post_parent = string $subpost = string $subpost_id = string $attachment = string $attachment_id = integer $name = string $static = string $pagename = string $page_id = integer $second = string $minute = string $hour = string $day = integer $monthnum = integer $year = integer $w = integer $category_name = string $tag = string $tag_id = string $author_name = string $feed = string $tb = string $comments_popup = string $meta_key = string $meta_value = string $preview = string $s = string $sentence = string $fields = string $category__in = array $category__not_in = array $category__and = array $post__in = array $post__not_in = array $tag__in = array $tag__not_in = array $tag__and = array $tag_slug__in = array $tag_slug__and = array $ignore_sticky_posts = boolean $suppress_filters = boolean $cache_results = boolean $update_post_term_cache = boolean $update_post_meta_cache = boolean $post_type = string $posts_per_page = integer $nopaging = boolean $comments_per_page = string $no_found_rows = boolean $order = string |
$_template_file = string $require_once = boolean $posts = array $post = object $wp_did_header = boolean $wp_did_template_redirect = NULL $wp_query = object $wp_rewrite = object $wpdb = object $wp_version = string $wp = object $id = integer $comment = NULL $user_ID = integer $cat = string $paged = integer $error = string $m = integer $p = integer $post_parent = string $subpost = string $subpost_id = string $attachment = string $attachment_id = integer $name = string $static = string $pagename = string $page_id = integer $second = string $minute = string $hour = string $day = integer $monthnum = integer $year = integer $w = integer $category_name = string $tag = string $tag_id = string $author_name = string $feed = string $tb = string $comments_popup = string $meta_key = string $meta_value = string $preview = string $s = string $sentence = string $fields = string $category__in = array $category__not_in = array $category__and = array $post__in = array $post__not_in = array $tag__in = array $tag__not_in = array $tag__and = array $tag_slug__in = array $tag_slug__and = array $ignore_sticky_posts = boolean $suppress_filters = boolean $cache_results = boolean $update_post_term_cache = boolean $update_post_meta_cache = boolean $post_type = string $posts_per_page = integer $nopaging = boolean $comments_per_page = string $no_found_rows = boolean $order = string
Incoming search terms:
- wordpress global variable have_posts
- $post__not_in array wordpress
- global variables available for wordpress
- $cat global variable wordpress
- wordpres reserved post and get variables
- wordpress $w variable
- WordPress defined variables
- wordpress defining global variables
- wordpress get defined variables
- wordpress global array category

