The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> PHP Variable in Wordpress Shortcode, Variable won't transfer over to shortcode...
Dante Monaldo
post Feb 25 2012, 02:58 AM
Post #1


Advanced Member
****

Group: Members
Posts: 124
Joined: 22-March 09
From: California, USA
Member No.: 8,132



I wrote a simpe PHP script and have been trying to return the results in WordPress shortcodes, but I can't seem to get it to work. Here is what I have:

CODE
function securetotal() {
    return $secure_total;
}
add_shortcode('secure', 'securetotal');


$secure_total is the predefined variable that I need to be displayed. I can display simple text instead of the variable, but the variable is not transferring any results. Am I missing something? Any ideas?

BTW, I did post this on the Wordpress forum, but didn't get any replies, so I'm hoping someone here can shed light on it. Help is much appreciated.


--------------------
~ Dante Monaldo
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Feb 25 2012, 04:48 AM
Post #2


Jocular coder
********

Group: Members
Posts: 2,212
Joined: 31-August 06
Member No.: 43



QUOTE(Dante Monaldo @ Feb 25 2012, 04:58 PM) *

I wrote a simpe PHP script and have been trying to return the results in WordPress shortcodes, but I can't seem to get it to work. Here is what I have:

CODE
function securetotal() {
    return $secure_total;
}
add_shortcode('secure', 'securetotal');


$secure_total is the predefined variable that I need to be displayed. I can display simple text instead of the variable, but the variable is not transferring any results. Am I missing something? Any ideas?


That fragment on its own does not mean much. But...

securetotal() will generally return NULL, since $secure_total is not defined, and not global. Perhaps you need to make it global?

Where's the manual for add_shortcode()? I presume this is Wordpress...? Please give a link or copy the function description.

But currently the arguments are just two strings 'secure' and 'securetotal', with no obvious connection to the rest of the fragment.


--------------------
Brian Chandler
Nothing in this post constitutes "commercial solicitation". PayPal does not solicit residents of Japan. Contents may settle in transit. "Legal mind" may or may not be brain-damaged.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Dante Monaldo
post Feb 25 2012, 12:08 PM
Post #3


Advanced Member
****

Group: Members
Posts: 124
Joined: 22-March 09
From: California, USA
Member No.: 8,132



Okay, the problem was that the variable was not global.

I just had to make $secure_total global and that fixed the problem. Thanks!

Here's the code just in case anyone else has the same problem.

CODE

function securetotal() {
       global $secure_total;
       return $secure_total;
}
add_shortcode('secure', 'securetotal');


This post has been edited by Dante Monaldo: Feb 25 2012, 12:08 PM


--------------------
~ Dante Monaldo
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 23rd July 2014 - 09:18 PM