The tag has no wiki summary.

learn more… | top users | synonyms (1)

1
vote
2answers
73 views

Should I global $wpdb outside of any of my plugin's functions scope?

I know that the general advice to global variables is to not use them at all. Still, when doing something with the Wordpress database, it is required to do global $wpdb; to access the methods ...
0
votes
1answer
26 views

Understanding WordPress Search

I am trying to create a custom search similar to the one on totaljobs.com but through a WordPress site. Essentially I would be able to search for both search terms and location simultaneously. The ...
0
votes
1answer
19 views

Current URL path variable

WordPress has a built-in variable $pagename that will give the current page. I am looking for something that will give the full url including the path before the current page. Details below. I am ...
0
votes
2answers
39 views

Using global $post; to get featured image for custom post via WP_Query

I'm using a site-wide function to add css to the <head> of the page pull in featured images of various as a responsive page background. It works great across the rest of my site but fails on a ...
0
votes
0answers
23 views

Global post is always custom post type last post

my global $post is always taking the object of my custom post type "advertisement". So when i'm editing e.g. "Hello world" which post id is 1, it shows me post id of the last advertisement post. If ...
1
vote
1answer
48 views

Global functions on WPMU

I work in a multisite environment where all of the sites are related. A lot of recent developments have required me to copy and paste certain functions into many different theme folders, which causes ...
0
votes
2answers
25 views

Test if php document executed by Wordpress or directly

Active plugin PHP files are interpreted automatically when you view a page, post, admin page, etc. I could also run a plugin PHP directly if I knew the fully qualified URL, however it will most ...
0
votes
1answer
16 views

What's the right way to share data between widgets?

I've got a few custom widgets in my site, which I'm targeting to specific tags. There may be a case where there may be an overlap in widget targeting, and the desirable behaviour may be to only show ...
0
votes
1answer
20 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
11 views

Use admin notices to show errors [duplicate]

I'm using the transition_post_status hook to perform some operations after publishing a post. If an error occurs, I would like to use the admin notices to show a message to the user: ...
0
votes
1answer
67 views

How can I save custom meta to one global value?

I have added a custom meta box to one of my custom post types. It contains a checkbox that will indicate that this is the "featured monthly product" (there can only ever be one). When I check this ...
0
votes
1answer
45 views

Display Post Meta in Header

I'm trying to get page post meta in my header so I can set some meta tags. I tried to get the global post variable but it only return true. <?php global $post; global $wp_query; echo ...
1
vote
2answers
108 views

What are the disadvantages of using global variable?

I am a newbie at WordPress. In my "recent posts" shortcode, I used global $post variable, because the_title() function was giving me page's title, not post's title. I am not exactly sure, but I ...
0
votes
0answers
64 views

global variable not accessable inside functions

I downloaded and installed a wordpress plugin. Everthing works fine on localhost untill i uploaded the site on live server it wasn't working as intended. When i define a variable as global its value ...
0
votes
1answer
103 views

How to get particular data from wp_list_comments outside the loop?

I need some help,very much new to wordpress. I need only comment title and comment date from wp_list_comments function in my post, calling from outside loop, after declared $postid as global ...
0
votes
0answers
48 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
2answers
232 views

Is $page a global variable in wordpress?

I am having a problem with a local $page variable, especially when using it in The Loop. Is it a reserved variable of Wordpress? Also where can I find a list of all those global variables?
0
votes
0answers
31 views

global vars in wordpress no works fine

I have 2 global vars defined inside funtions.php global $ruta_path; global $ruta_db; I want send the value of this global values to function in comments but no get works Inside comments.php i have ...
0
votes
1answer
95 views

Detecting Embed URLs Within post_content

I need to change the way WP outputs html when given an embed URL within the content. Example content within the WP editor: This is standard content and will be wrapped in a 'p' tag. But check out ...
5
votes
2answers
156 views

What is the difference between using global $current_screen and get_current_screen()?

I have been looking at get_current_screen();. I have seen there is also a global $current_screen; that I could use. Here are two examples: // Using function function wpse_post_notice() { ...
0
votes
1answer
37 views

how do i register global query in template

ok i think this is a basic php question but here goes: i have this working code: <!-- show the bands playing --> <?php $child_posts = ...
0
votes
1answer
54 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 ...
0
votes
0answers
19 views

WordPress Optional Panel Global variable [duplicate]

I am creating a WordPress options panel based on http://en.bainternet.info/2012/my-options-panel In the article it states to call the stored options to use //get the data to an array $data = ...
0
votes
2answers
82 views

Will $current_user no longer be global?

I just had a look at Global variables in WP and I discovered that a lot has changed since the last time I looked. $current_user is no longer listed. Does that mean this and many other (old) globals ...
0
votes
1answer
23 views

How to save a viewer specific option

A minimal example of my problem would be default background colour is white a custom sidebar widget offers to switch background colour to green when switched to green, background shall stay green ...
4
votes
1answer
177 views

Registering AJAX callback function that is part of a class without instantiating the class in function.php

I'm not even sure if this is possible. But nevertheless I thought of asking. I'm in habit of wrapping/grouping AJAX calls for a particular need within a class. See below. class my_class { ...
0
votes
3answers
52 views

Is a multisite install what I need?

I have a client who owns a chain of clubs - all of them unique and requiring different sites, however, there will be one GLOBAL login for members. The members area will include things like club ...
0
votes
0answers
21 views

Advice or Best Practice on setting attributes and properties for user on login

I’m working on a web application service which is going to use a lot of the built-in Wordpress functionalities but also relies heavily on some customized code and tables to create - among others - ...
2
votes
1answer
2k views

get_query_var vs global query variables?

I have query vars defined in functions.php using: add_filter('init', 'add_query_vars'); function add_query_vars() { global $wp; $wp->add_query_var('profession'); } Until now, to ...
0
votes
1answer
321 views

No access to global variables?

In main.js, I have a script, which is sending an ajax request to script.php. $.ajax({ type: "POST", url: "wp-content/themes/roots/script.php", data: registerdata, success: ...
1
vote
3answers
10k views

How to set and use global variables? Or why not to use them at all

UPDATE: My original question has been solved, but this is turning into a valid discussion about why not to use global variables, so I am updating the question to reflect that. The solution was ...
1
vote
2answers
985 views

Using query_posts inside single.php loop

Inside of my loop in single.php, I used a custom query using get_posts to return posts belonging to a certain category. <?php global $post; ...
1
vote
2answers
2k views

Defining a global array in functions.php?

I try to create an array of years, which is avaible in my template-files and in at least one other function in the functions.php. function get_the_years() { global $year_arr = range(2001, ...
0
votes
1answer
142 views

using 1 form shortcode (si or cf7) for all multisite sites

I have a network with more than 50 sites. I want to create one contact form (which means one shortcode) using contact form 7 or fast secure contact form. Then, I want to use that shortcode on all the ...
9
votes
2answers
359 views

What is a good alternative to using $content_width for image optimization?

The $content_width GLOBAL in WordPress effects many themes and even some plugins by limiting the size of images and embeds in posts, it is a requirement for themes submitted to wordpress.org. It is ...
0
votes
1answer
85 views

The $post variable – Did I get the grasp of how the Backend actions get parsed?

I was looking for a way to attach a custom meta box to the edit screen of a page at a specific template. I found and tried this here and from my actual point of view this can't work that way. Let me ...
0
votes
2answers
4k views

How to set global variable in functions.php

I want to be able to echo the URL of the featured image of a post and after looking some on the web I found the following which works fine when I put it in a loop in my front page template. <?php ...
1
vote
2answers
211 views

Retrieve the template directory URI via global or get_template_directory_uri() every time?

One Wordpress function I happen to use frequently is get_template_directory_uri(). While I tried to minimize or avoid its use where I can, I still happen to have more than one call to this function in ...
1
vote
1answer
391 views

Using global $post v/s $GLOBALS['post']

It's probably more of a PHP question, but I would like to know if there are any differences in using global $post; echo $post->ID; when compared to echo $GLOBALS['post']->ID; to access the ...
0
votes
1answer
427 views

get_posts() and global variables

I was reading this post: When should you use WP_Query vs query_posts() vs get_posts()?, which seems to have become the go-to post for understanding the difference between the different functions for ...
1
vote
1answer
103 views

Change global values from templates

I am trying to check for a php variable in each of my template in order to assign it a different styling but the value seems to disappear, can you please help, I already spent hours trying to figure ...
1
vote
1answer
627 views

How to make global post work with custom post type?

I was wondering to know if it's possible to use global posts with custom_types. I was working with this function: global $post; $myposts = get_posts('numberposts=4&offset=1& category=3,4'); ...
2
votes
1answer
349 views

Pass variables from one widget to another widget

I wrote a widget but I need to use the variables from one widget in another...both widgets are in the same dynamic sidebar. This is what I am trying to do: I wrote a widget that adds a footer to the ...
0
votes
1answer
610 views

Passing global variable from header.php to functions.php

Situation: Is header.php file where is code: if(is_single()){ global $my_global_var; $my_global_var == true; } Is functions.php file where is code: global $my_global_var; if($my_global_var == true) ...
0
votes
4answers
494 views

Does WP have a global of $id?

I'm trying to attach an object to every post of any type. This will require post ID to populate or create my object. So, I either call global $post, or get_the_ID(), or do get_post(). I hope there is ...
0
votes
1answer
109 views

How to check if this is the nth instance of a given shortcode in a post

Suppose I have a shortcode called [item], which I have used 20 times in a particular post. Is it possible, from within the shortcode handler function, to know what the numerical index of the given ...
-2
votes
1answer
273 views

How do I access variables outside a function [closed]

I have a custom function which defines a bunch of variables. I would like to be able to call this function from inside a loop so I can have access to all its variables, like so: functions.php ...
1
vote
2answers
113 views

How should I store global information such as a phone number so that it is editable through the CMS?

Right now I have a p element in header.php containing the address and phone number my client wishes to use for contact info. How can I set this up so that it is editable through the WP admin area so ...
1
vote
1answer
430 views

Passing variables to templates (alternatives to globalizing variables)

I want to make my WP code simpler (there's some mess within header.php, page.php etc.). So, for example, I want to set something like this global: $foo = get_option('foo'); So $foo will work ...
0
votes
1answer
194 views

Where is this function's callback getting its arguments from?

This might be better suited to Stack Overflow, thought I'd try here first though. I was walking through this tutorial by Justin Tadlock and encountered the function below being used as the callback ...