Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [globals]

In PHP globals are variables that are available for every function. WordPress core defines several handfulls of global variables, such as `$post` and `wp_query`.

41 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
2answers
879 views

Accessing $post global on a custom post type archive page

I have a custom post type called projects, and its archive is at /projects, on the archive page I get notices Notice: Trying to get property of non-object every time I try to access the $post i.e. $...
2
votes
2answers
845 views

Custom plugin: Trying to show saved data on frontend

I'm working on my first plugin and I have made a nice settings page which saves and works. But I have split it to few files and now I can't determine if field is checked.. I have also tried ...
1
vote
1answer
325 views

Global $post not working in OOP function WordPress

I added a custom field with comment form. Below is my code.First function return post id when using var_dump function.But the last function return NULL always. class Post_Rating_Public_Helper { ...
1
vote
1answer
82 views

How to access plugin variables from theme templates without using globals?

Is there a way to access plugin variables from the theme template files without using globals? I have the following situation: One plugin function validates POST data submitted in a form. If ...
1
vote
0answers
42 views

Assign External Database Queries to Global Variables and Make Them Accessible

I've got a bit of a tough question involving a website and its web app counterpart. The Background The website relies on two different databases: its default, named wp_website, and its counterpart's ...
0
votes
0answers
25 views

Insert variables into wpdb in custom post template

I'm rewriting this to try to make it easier. I am inserting into a database table information which is sent when I click on a button in the page. When I insert the data it works, unless I try to ...
0
votes
0answers
7 views

API Function to use in place of global $menu?

Just wondering... Googling it I cannot find it. I'd like to not depend on globals at all in any circumstance.
0
votes
0answers
29 views

What is the correct way to obtain access to the WP_oEmbed object?

I know that WP_oEmbed is a class used by WordPress to handle oEmbeds. Is this available as a global or should I create a new instance of it? Update: I have found a function called ...
0
votes
0answers
21 views

Browser detection booleans mess. Caché plugin?

Hello, I have an issue concerning the Browser Detection Booleans. Sometimes, being in Chrome or Firefox, the page is served as being in IE, as in the attached image. Can this be related to the fact ...
0
votes
0answers
211 views

Trying to get property 'post_content' of non-object

I'm creating a wordpress theme and I created a shortcode to show an abstract of a post (the first image, title, and link) from a post (by its ID). To do this, I created a function to get the first ...
0
votes
0answers
14 views

using global variables and performance

I use global variables to retrieve all sort of available data, especially $post and $posts, for example in order to retrieve the url of a user from the post loop instead of using ...
0
votes
0answers
40 views

Simple global, in-memory, persistent object for storing result of stemming a relatively large JSON blob

I'm relatively new to WordPress. I have this 2.6 MB json file: https://raw.githubusercontent.com/codeforamerica/naics-api/master/data/naics-2012.json It's a list of around 2000 entries where every ...
0
votes
0answers
40 views

How to access custom class methods from any include without using global

I am trying to do the following functions.php class Test { public function hello(){ return 'Hello'; } } $test = new Test(); header.php or any other include echo $test->hello();...
0
votes
0answers
14 views

How do I get a reference to the HTML memory buffer while the page is being constructed?

I want to view & update the buffer with html "<head>" data section in it, after the head has been generated. Problem statement: I have created some shortcodes in a plug-in which, if ...
0
votes
0answers
100 views

global $wp_meta_boxes returns NULL

When I call global $wp_meta_boxes; it returns null. I'm trying to calling like: class my_class() { public function __construct(){ add_action( 'wp_dashboard_setup' , array( $this , '...
0
votes
0answers
124 views

Ajax global variable is not getting saved (returns null)

I am trying to modify a global variable $lath , It is a shortcode. This is where i have defined it. function listing_order(){ global $lath; $lath = array('email','phone'); foreach ($lath ...
0
votes
2answers
212 views

Current page id returns the incorrect value

I need to capture the current page id, execute some conditional script in footer, in my own plugin function hooks to wp_footer. Here is my plugin code, but page id returning wrong value? <?php /* ...
0
votes
1answer
127 views

$GLOBALS['value1'] is not working

My custom PHP script works on my PC over localhost. But, when I upload my code to the 'live' WordPress site, The $GLOBALS values are just null even they work on my localhost. (Nothing wrong with the ...
0
votes
0answers
30 views

wp localize script makes variable global, how to solve that?

I don't want my variable "infinite" to be global variable. but it's like wp_localize_script would make it global automatically. How to solve that? This is my code. Wordpress php file: public ...
0
votes
1answer
48 views

using globals from wp_link_pages function

I'm following this reference page for wp_link_pages:https://developer.wordpress.org/reference/functions/wp_link_pages/ In it, 4 global variables are declared: $page, $numpages, $multipage, $more. I'...
0
votes
1answer
44 views

global variables in templates

I have defined a global variable in one of my template files page.php. I can access the global variables in my loop. But when the loop displays an individual post in single.php, the variable has no ...
0
votes
2answers
91 views

Get variable from previous blog while using switch_to_blog

I'm writing a query that switches to the main blog of a MU site using switch_to_blog(). All is well except i'm attempting to write a wp_query that includes a variable needed from the previous blog. ...
0
votes
1answer
1k views

Ajax Pagination on Ajax filter

Following this great tutorial I've implemented Ajax pagination with scrolling: https://www.billerickson.net/infinite-scroll-in-wordpress/. Now, I've added a second Ajax call to filter the posts by ...
0
votes
1answer
75 views

Need data from two different actions

I have two functions on my functions.php Both functions are from a plugin and I'm trying to use this variable $answerIndex in the other action to do the if condition. The issue is I'm trying with ...
0
votes
1answer
447 views

global categories - Share specific categories in wordpress multisite

I have a wordpress multisite network. So I want to share just some categories between subsites.
0
votes
1answer
123 views

Use a select box to change a php variable

I am currently stuck on a little problem. I'm using a localStored value to differentiate the content that user sees depending on their choice. <div class="form-group form-inline hidden-print"> ...
0
votes
2answers
629 views

How do I pass custom shortcode-extracted variables (taxonomy) into a query function for WordPress RoyalSlider?

Plugin in question: http://dimsemenov.com/plugins/royal-slider/wordpress/ Background: This is a great plugin, and it features a 'post' version where the slider pulls content from posts. However, the ...
0
votes
2answers
89 views

Save last login date in global before change it?

I use this function to get the last time a user logged in. function jkn_last_login($user_login) { $user = get_user_by( 'login', $user_login ); global $last_login; $last_login = array(); ...
0
votes
1answer
52 views

apply_filters to $GLOBALS

I'm building a onepage website, using the Pootle Page Building plugin. With get_page, I show every separate page on 1 page. To target the Pootle Page Builder content, I'm using the following code: $...
0
votes
0answers
689 views

Setting a cookie in functions.php and it gets deleted when working on an other function

My first function gets the parameters from the URL and sets the cookies: /** Get variables from the URL and set them into the coockie **/ add_action( 'init', 'set_utm_cookie'); function ...
0
votes
0answers
114 views

Popup panel is only displaying 1 entry ignoring all others

I have a popup panel being used for when someone clicks on view bio it will display their bio along with their name and headshot. As of right now I have four members being displayed M1 M2 M3 and M4. ...
0
votes
0answers
66 views

Best way to access variables in template markup

I am making my own mini OOP wrapper for working with wordpress themes. I have a main $settings variable that contains all of the information like definitions, scripts, menus etc.. I then pass this ...
0
votes
1answer
154 views

Editing Global Variables from Inside Functions

I'm working on my first plugin and I have two separate functions inside to accomplish two different task. Each function is added to a different hook, one using actions and the other using filters. ...
0
votes
1answer
26 views

Settings in functions.php used by a plugin

I'm writing a simple plugin and want some settings in an array in the functions.php file. I'm thinking of adding this in the theme functions.php $test = array('haha' => 'hehe'); my_function( $...
0
votes
0answers
59 views

Add notice to add image popup

I have been using the global $pagenow variable to add instructions for users, but I need to somehow hook into the add image popup as I would like to instruct the users on optimal resolution for ...
0
votes
0answers
264 views

How to load post_meta for custom post type via Ajax

I'm trying to load a YouTube video via ajax outside the loop. I have it working on regular pages, but not anything loaded via ajax. A user would click a button, then a YouTube video will load via ajax,...
0
votes
0answers
89 views

Sessions in plugin development?

I'm developing a plugin. At present I have two files. dotmailer.php and dotmailer-add.php. I'm creating a newsletter widget. My dotmailer.php plugin adds an admin menu, with options. It allows the ...
0
votes
1answer
438 views

Save something to global var in add_filter

I am here again with a strange question. First, I'm using ACF plugin for adding cistom fields. My code looks somethink like that: global $testMe; $testMe = 0; function my_acf_update_value( $value, $...
0
votes
0answers
146 views

Wordpress $GLOBALS and PHP $GLOBALS

Is the php $GLOBALS associative array over written in WordPress with the WordPress $GLOBALS? I have a piece of code that uses $GLOBALS['myvariablename'] to access a global variable. It works in php, ...
0
votes
1answer
193 views

key( $GLOBALS['wp_registered_sidebars'] ) is always showing the same value

I am using this code from another answer add_action( 'dynamic_sidebar', 'wpse_96681_hr' ); function wpse_96681_hr( $widget ) { static $counter = 0; // right sidebar in Twenty Ten. Adjust ...
-1
votes
1answer
21 views

Wordpress Multisite and site speed and scaleability

We have a multisite wordpress setup like this: domain.com/nz domain.com/au domain.com/us etc. I would like to know the best approach for the best setup so we can give each country the best site speed ...