1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Wordpress - require file

Discussion in 'PHP' started by mrki444, Jul 24, 2017.

  1. #1
    Greeting.

    I work in Wordpress on one project and I need help.

    What is it about?

    I made the file data.php where certain data is generated. Now I have to access that file, take variables, and print their values in the title and body of the post.

    I succeeded to print the post to the post body using the following code line
    <?php require "data.php"; echo $vrbody; ?>
    Code (markup):
    That does not work in the title. I think the problem is in the require function, because this line in title works
    <?php echo $vrtitle='Some title'; ?>
    Code (markup):
    I've tried in the header.php theme file use require function
    <?php require "data.php" ?>
    Code (markup):
    then put following line in the post title
    <?php echo $vrtitle; ?>
    Code (markup):
    but failed. I've been trying to load at few more places desired file (functions.php, wp-config.php), but it has also failed.

    Can I somewhere load my file so that I can access variables in post title without reloading file?
    Thanks for help.
    Sorry for bad English.
     
    mrki444, Jul 24, 2017 IP
  2. Blank ™

    Blank ™ Well-Known Member

    Messages:
    223
    Likes Received:
    18
    Best Answers:
    6
    Trophy Points:
    110
    #2
    
    <?php require "./data.php"; echo $vrbody; ?>
    
    PHP:
    Still nothing?
     
    Blank ™, Jul 24, 2017 IP
  3. mrki444

    mrki444 Greenhorn

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    Sory, no.
     
    Last edited: Jul 24, 2017
    mrki444, Jul 24, 2017 IP
  4. mrki444

    mrki444 Greenhorn

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    I'm using Allow PHP Execute and Insert PHP plugin. Could they making a problem?
     
    mrki444, Jul 24, 2017 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    May I ask WHY you're doing this? I mean... unless all your posts are the same post, I'm guessing you don't need the same information for every one. Then why create this "data.php"-file? Can't you just utilize the database as it should be utilized? And IF you need the same information on ALL posts... then why not just add it to the single.php-file in the themes folder?
     
    PoPSiCLe, Jul 24, 2017 IP
  6. mrki444

    mrki444 Greenhorn

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #6
    We actually scraping data from other our sites, do some calculations and generate reports. Idea is one report one post so we need collect post title and post body from that file.
     
    mrki444, Jul 24, 2017 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    Then why don't you create something that inputs the information into the database, making it part of normal WordPress posts, making it easily searchable and so on?
     
    PoPSiCLe, Jul 24, 2017 IP
  8. mrki444

    mrki444 Greenhorn

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #8
    Good idea. Thanks. We are going to try both ways solve problem. I hope boss and rest od team will agree.
     
    mrki444, Jul 25, 2017 IP