How does WordPress make its functions globally available?

Themes and plugins are just files that are loaded alongside all the other WordPress files that contain its functions, and those are all loaded whenever WordPress is run. So there’s no special trick or anything weird going on. WordPress just loads the files that contain these functions before it loads themes and plugins. Keep in … Read more

Echo get_the_category() outside of loop (global?)

I realized that the_title(); can parse in file1.php outside of the loop, so why can’t the category and ID? The following solved my issue. // file1.php <div> <h1><?php the_title(); ?></h2> <?php $category_array = wp_get_post_categories($post->ID); $category_list = array(); foreach ( $category_array as $categories ) { $category_list[] = get_cat_name( $categories ); } $lister = implode(‘ • ‘, … Read more

Current page id returns the incorrect value

To get the current page ID outside of The Loop, you need to use get_queried_object_id(); ($wp_query-> is unnecessary). However, this will only work when you are viewing a single Page (so anything under Pages > All Pages in the back-end). If you are viewing the blog, an archive, or a category it will not be … Read more

Is $page a global variable in wordpress?

Yes. It is an “inside the Loop” global. $page (int) The page of the post, as specified by the query var page. http://codex.wordpress.org/Global_Variables It is setup and used by setup_postdata which executes at every iteration of a standard Loop. Though meant for use inside the Loop, the variable would still be set after the Loop … Read more

Will $current_user no longer be global?

The $current_user is still a valid global, however like all globals, you should avoid relying on them. If you need the current user in a function, do this instead: $current_user = wp_get_current_user(); Also be aware that this may return false if no user is logged in on the current request, while the global $current_user may … Read more

Change global values from templates

I think you could simplify much of what you are doing just by using the global $_SESSION variable. try something like this: add_action(‘wp_head’, ‘your_session_variable’ ); function your_session_variable(){ session_start(); $gender = isset($_GET[‘gender’]) ? $_GET[‘gender’] : $_SESSION[‘gender’]; $_SESSION[‘gender’] = $gender; } Now to access the session variable from the template make sure to use session_start() before grabbing … Read more

What is the global $wp object used for?

It contains the main instance of the WP class, which is primarily responsible for parsing the request URL and querying the appropriate posts, as well as sending headers and handling 404s. It can be used for things like getting the current request URL. If it’s declared in a function but not used, it’s likely a … Read more

get_query_var vs global query variables?

get_query_var() is a wrapper for $wp_query->get($var);. But the global $wp_query is not always identical to the one set up during the request. That’s the main problem with query_posts(). And other plugins can overwrite these variables unintentionally too. I have seen plugins putting $i into the global namespace … And the return values are different: $GLOBALS[‘missing_var’] … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)