PHP in WordPress - Setting & Accessing Variables

5 replies
I'm using Exec-PHP to execute code, and it's working.

I want to be able to set a variable once upon & access that variable in individual posts.

I tried putting the code in header.php, then about everywhere else.

But when I put

<?php echo $var_name; ?> in the post, it's blank.

Help?

thanks,
PCRoger.
#accessing #php #setting #variables #wordpress
  • Profile picture of the author mywebwork
    Did you try using a session variable? That should persist through pages.

    Just a thought.

    Bill
    {{ DiscussionBoard.errors[1788217].message }}
  • Profile picture of the author PCRoger
    That worked, thanks.

    Do you happen to know how to reference a file that is in

    http://mydomain.com/../includes/filename') with all the appropriate number of "../" but it never works.

    Had to duplicate the file in the directory of that theme.

    Ideas on that?

    thanks.
    Signature
    Track your affiliate sales back to the ARTICLE or WEBSITE that generated the sale. CBSaleTracker

    I was making money in days with the 4 Day Money Making Blueprint

    {{ DiscussionBoard.errors[1788748].message }}
    • Profile picture of the author Dan Liptak
      Originally Posted by PCRoger View Post

      That worked, thanks.

      Do you happen to know how to reference a file that is in

      http://mydomain.com/../includes/filename') with all the appropriate number of "../" but it never works.

      Had to duplicate the file in the directory of that theme.

      Ideas on that?

      thanks.
      Not sure if WP is in the root of your domain or not. If it is then you could try the ABSPATH like require_once( ABSPATH . 'includes/file.php' );
      {{ DiscussionBoard.errors[1789570].message }}
  • Profile picture of the author PCRoger
    WP is in /blog.

    thanks,
    PCRoger.
    Signature
    Track your affiliate sales back to the ARTICLE or WEBSITE that generated the sale. CBSaleTracker

    I was making money in days with the 4 Day Money Making Blueprint

    {{ DiscussionBoard.errors[1793083].message }}
  • Profile picture of the author Dan Liptak
    You will need to find the path yourself. It isn't too hard. Just create a path.php file in your includes directory.

    PHP Code:
    <?php
    echo dirname(__FILE__);
    ?>
    Now load it up in your browser and it will output the path. Something like /home/user/public_html/includes.

    Then you can do require_once('/home/user/public_html/includes/includefilename.php')

    Later,
    Dan
    {{ DiscussionBoard.errors[1793728].message }}

Trending Topics