The globals tag has no wiki summary.
1
vote
1answer
23 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
34 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 ...
2
votes
1answer
160 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
0answers
8 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 - ...
1
vote
1answer
81 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
61 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
votes
3answers
331 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 ...
0
votes
2answers
97 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
170 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, ...
8
votes
2answers
191 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
52 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
5answers
1k views
How to include code only on specific pages?
I'm learning about plugins and shortcodes. I noticed that when I activate my plugin its code gets loaded on all of my pages-- even pages that don't have my shortcode. (I don't mean content vs. admin ...
0
votes
1answer
59 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
948 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
72 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 ...
0
votes
1answer
118 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
164 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 ...
0
votes
1answer
872 views
How to call a function only once (global variable scope)
I have been trying to work out the most effecient way to use functions in WordPress.
I have a big slow function big_slow_function() that ideally is only run once. But I need to use the boolean that ...
7
votes
4answers
4k views
WordPress Multisite - global categories
Setting up a WP multisite instance - the client has an existing ontology / set of categories that they want to classify all content across the set of blogs. Also the desire is that any new categories ...
1
vote
1answer
61 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
264 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');
...
4
votes
2answers
3k views
query_posts() in function makes global $wp_query out of sync?
This has me stumped for a while already. Either I am missing something very obvious or something very not obvious. I am also not entirely sure if this has something to do with WP or purely PHP ...
0
votes
1answer
370 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
196 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
60 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 ...
0
votes
1answer
271 views
How to show avatar of current logged in user in a widget
I have a php widget, and I need to show the avatar of the current logged in user, and I'm calling this code: <?php echo get_avatar(); ?>
But its only outputting the default avatar.
Is there a ...
3
votes
1answer
528 views
How to pass arguments from add_settings_field() to the callback function?
I have a function like this:
add_settings_field( 'contact_phone', 'Contact Phone', 'settings_callback', 'general');
That works. It calls settings_callback. Cool. The problem I have with this is: ...
-2
votes
1answer
83 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
80 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
214 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
96 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 ...
4
votes
4answers
889 views
Where to get information about array fields in $_REQUEST?
I just started to learn PHP and doing things with WordPress and I am a bit confused about information in Codex. Was told that Codex got all info I required but I got stuck with it.
What array fields ...
0
votes
2answers
469 views
How can i use a global variable in a .css file generated with php?
I am including a .css which i parse with php like so
<link rel="stylesheet" type="text/css" media="all" href="<?php echo get_childTheme_url(); ?>/css/productgallery.php" />
Now in ...
1
vote
1answer
411 views
wp_get_current_user always returns 0 continued
I have been busting my head trying to get the user ID with every piece of code possible but it always comes back "0". Not sure what I'm doing wrong. I started out using this:
<?php $user_info = ...
0
votes
2answers
535 views
Using global $post; with custom post types
I'm working on creating a notification that will indicate when a post is less than a few days old. This is specifically for a custom post type called "news". Is there a way to use global $post; with ...
0
votes
1answer
339 views
What does the Global Variable $s represent?
What does the $GLOBALS['s'] variable contain? It looks like an empty array, but what would it normally hold?
I've encountered it in a tutorial: The WordPress Theme: Single Post, Post Attachment, ...
0
votes
1answer
90 views
How to avoid repeatedly use the new statement to instantiate a class? [closed]
I have a Class with a lot of variables.
To get a variable, I have to write this line in each function:
$x = new MY_Class();
I guess there has to be another way?
I tried:
function my_data(){
...
0
votes
1answer
369 views
Difference between $numpages & $max_page on archive pages
After taking a look at global $max_page; and global $numpages; on category-archive pages (is_archive() || $GLOBALS['wp_query']->is_archive returning true), I see the following return values:
...
1
vote
1answer
424 views
How/where is the global variable $wp_registered_widgets filled?
I have a problem of widgets not showing up, trying to investigate why $wp_registered_widgets is empty.
Can somebody tell me where it gets filled from the database? How can I find out why the default ...
0
votes
1answer
260 views
SFTP define in wp-config.php
just wondering if theres a way to define sftp info in wp-config.php the same way you can with ftp.
makes plugin adding a lot easier!
best,Dan.
0
votes
2answers
2k views
Get current page id, title, url, etc
Sorry but I get lost on Wordpress's codex.
I am trying to add a mail this page sharing link and want to include some info from the page.
In pseudo code is this possible?
<a ...
-1
votes
1answer
104 views
Checkbox on a custom menu [closed]
I have this code on a custom menu:
<form method="post" action="options.php">
<?php wp_nonce_field('update-options') ?>
<input type="checkbox" name="myoption[option_one]" ...
0
votes
1answer
37 views
What's the safest way to switch and restore a post global?
I need to switch WordPress's post context, sort of like switch_to_blog() but for posts. What's the safest way to alter WordPress's global state and switch it back?
1
vote
1answer
277 views
Getting $curauth->ID to work inside a shortcode
Im wanting to show a profile/logo pic on author.php via a simple shortcode:
function wpaluploader_showauthorimage() {
$wpaluploader_authorlogo = '<img src="' . get_bloginfo('url'). ...
4
votes
2answers
984 views
Does an activated plugin automatically mean its methods are available to other WP functions?
I made a WordPress plugin like this:
Class MY_CLASS {
//codes
}
Global $myclass;
$myclass = New MY_CLASS ();
After installed and activated the plugin, can I use this class in other plugins without ...
1
vote
2answers
591 views
Call External Object in Class Function During Callback
I've a class which has a function that check and creates table in database.
In order to do so i need to use WordPress $wpdb object.
I need the function to run only on first plugin activation, so i ...