Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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`.

0
votes
0answers
10 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
2answers
20 views

WordPress Image Slider Looping Title Not Working

In my index page there are two slider one is working fine but the second one is giving some problems. FIRST ONE <?php global $post; $i=0; $args = array('post_per_page' => -1, 'post_type' =>...
1
vote
1answer
82 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 { ...
0
votes
0answers
49 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
1answer
39 views

Relative redirects for posts, categories, products and product categories

I imported all content from an old site to a new one. The old site was basically a catalog of products and blog posts. However, it was all built as standard WP posts - not custom post types. The new ...
0
votes
0answers
57 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
59 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 /* ...
1
vote
1answer
174 views

Multisite Installation: how do I setup global search?

I run a multisite installation and my sites are bilingual. I would like to find out how I can setup global search. Are there decent plugins available that do this? Cos I'm a wordpress noob and am ...
0
votes
0answers
14 views

Have global footer that isn't applying globally?

I have a global footer set up but it's not applying across the site. There are 2 footers showing and they are quite similar, but they aren't the same. I used Beaver Builder to create the footer as a ...
0
votes
1answer
239 views

Global page ID variable empty error

I am creating theme and I have a need to create global variables within theme functions.php file. Currently I am doing it like this: /** * Setup globals */ global $nb_id, $nb_page; $nb_id = ...
0
votes
0answers
37 views

How to display value of custom fields on schema on taxonomy archive

I am trying to display the code <meta itemprop="name" content="<?php woocommerce_page_title(); ?>"> <meta itemprop="ratingValue" content="<?php echo get_post_meta( get_the_ID(), '...
0
votes
0answers
13 views

switch_to_blog author meta

I'm running WP Multisite (7 sites), I'm using switch_to_blog to get some posts from another blogs in my network, with posts i don't have any problems, but when i try to get for example author meta ...
0
votes
1answer
44 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
1answer
17 views

Creating a (global)-mapping

I'm making a mapping between page-id's and category-id's, that's being used several places. However I read from this post, that one should never use global variables if one could avoid it. But I ...
0
votes
2answers
414 views

Declare Global Variable In OOP PHP

I'm working on my Plugin & i wanted to declare one of the global wordpress variables which is $current_screen To Check whether The user is on the target page or some other page, my Approach was ...
3
votes
2answers
499 views

What is $post_id? is it a global variable in wordpress?

$post_id how it can be used while echoing posts in single.php? is it global variable?
-1
votes
1answer
51 views

$GLOBALS & global doesn't work [closed]

I have the following configuration: $GLOBALS['x'] = 1; add_filter( 'filter_hook', 'my_function', 10, 2 ); function my_function() { $GLOBALS['x'] = 2; } add_action( 'action_hook', 'my_function2'...
-1
votes
0answers
51 views

Im trying to supply the post ID to a plugin function in the plugin file. But instead of the value, its NULL

TY for opening my question! Im trying to update the meta key 'license' in a custom post that I have, with the ID of an existing WP post. So Im using a global variable to store the ID of the WP post ...
0
votes
2answers
119 views

Translation issue with global variables

I'm creating a plugin that supports internationalization. Everything is working fine, except for global variables. Strings in global variables will not get the appropriate translation. Explanation: ...
4
votes
2answers
1k views

Create a global variable for use in all templates

I used following code function userinfo_global() { global $users_info; wp_get_current_user(); } add_action( 'init', 'userinfo_global' ); in a file users.php , this file are call in inside ...
0
votes
1answer
33 views

Why is overwriting $GLOBALS killing the_content()?

I'm in the single.php and now need to use the_content() instead of just $post->post_content; for youtube embeds etc.– in other projects the_content() and apply_filters("the_content", ...) does ...
0
votes
0answers
30 views

Custom Variables are not being passed

Custom variables that are in a custom global.php file are not being passed to a homepage.php, I have set up as the static homepage for WordPress. It just gives null errors as if the variable doesn't ...
0
votes
0answers
27 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
43 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
261 views

I need some explanation on global $post [duplicate]

Sorry if this sounds like a dumb question but it's something that has bugged me for a while. I need some explanation on function custom_function () { global $post; } I understand from PHP that ...
1
vote
2answers
1k views

Global $post shows null in some of my custom post types archive pages

My english is not very good looking. I have several custom post types, 'noticias' (news) 'articulos' (articles), etc. In my functions.php i enqueue scripts and styles by post_id or post_type using a ...
0
votes
1answer
41 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 ...
-1
votes
1answer
46 views

Global Handle to Class unavailable in Plugin?

I am writing a custom plugin and calling the plugin functions using short codes on my wordpress page. global $db_handle; below declares the handle to the class 'DBController' global. if (isset($...
0
votes
2answers
77 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. ...
1
vote
1answer
1k views

How does the $post_type global variable work?

I need to output the name of the custom post type within archive.php and single.php. I would use something like this: if ( 'staff' == get_post_type() ) { $post_type = 'staff'; } echo '<div ...
0
votes
1answer
127 views

Getting the teaser text without overriding global variables

I am trying to make a WordPress theme, following the Wordpress Coding Standards - WPCS. In functions.php, I have a function to get only the teaser (text above the read more-tag). The function works, ...
1
vote
1answer
61 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 ...
2
votes
1answer
51 views

Adding a section to admin menu for global settings

Bear with me a moment as I am still relatively new to WP dev. I am currently building a custom site that loads certain blocks on pages using get_template_part(); . So for example, the home page ...
-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 ...
0
votes
1answer
875 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
137 views

Best way to pass variables around a WordPress site?

I'm building a membership site with a membership plugin right now. The different types of memberships are associated with IDs and I have to constantly do things like "show this if the ID is 4122 (i.e. ...
5
votes
1answer
437 views

Filtered query_vars becomes global. Why does this work?

For some reason that's not quite clear, when I add custom query_vars, they become available everywhere without the need of an accessor like global or get_query_var() // if your url contains the var ...
1
vote
2answers
724 views

How to modify a global variable in a function and use it on another function?

Final state: As Nathan Johnson stated, I change my plug in to a class, still can't use post id in increment_like function... <?php .... //irrelevant parts skipped class wpse_263293 { protected ...
-1
votes
1answer
176 views

$do_not_duplicate is not working in genesis theme

I'm using Genesis child theme and I am using this function to display feature posts on home page. function modern_motoroids_extra_feature_posts(){ ?> <?php $do_not_duplicate = array(); ?...
2
votes
0answers
40 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
1answer
53 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
353 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.
2
votes
1answer
3k views

Passing variables to template parts

I have one template file videos.php which has the following line of code in it (aswell as a load of HTML): <?php get_template_part('loop', 'feed-videos' ); ?> inside that template part, I have ...
0
votes
2answers
143 views

Use global variables or function that returns said variables for site-wide private-ish WP settings?

I have a lot of functions extending various plugins and providing logic for a site, functions which use different bits of info that I would like to keep in one place and access it, but feel ...
0
votes
1answer
51 views

Filter the blog's title without using global variables

The below code uses the bloginfo filter to add some CSS rules to my blog’s title and outputs it to the site header, without affecting the HTML head’s <title> tag. This solution was taken from ...
2
votes
2answers
180 views

Filter the blog title displayed in the header

I wanted to filter the blog title displayed in the header to apply different CSS styles to different title parts/words, so I added the below function to my (WP 4.7) Twenty Seventeen child theme's ...
0
votes
1answer
113 views

Recommendations on accessing current user data in WordPress

While reading the following WordPress Codex page on Global variable usage, there is a bold line that states ** Accessing other globals besides the ones listed below is not recommended. ** My ...
0
votes
1answer
153 views

WP user agent returns random variables

I am using a PHP function in order to return the user browser, using the WP global variables. It used to work perfectly, but recently it started doing random things on Safari. I use chrome and ...
0
votes
1answer
115 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"> ...
1
vote
0answers
19 views

Pass updated local variable between functions? [duplicate]

I creating functions in my function.php and I have a question regarding passing local variables between functions. Let say I have the functions below, A and B, and I have the variable $amount. Now ...