Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6719011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:02:30+00:00 2026-05-26T09:02:30+00:00

I am creating a plugin for WordPress. I created a simple PHP file: Test.php.

  • 0

I am creating a plugin for WordPress. I created a simple PHP file:

Test.php. I can access that via browser but when I do:

<?php

global $wpdb;
global $wp;

?>

My wpdb and wp are NULL. Can anybody tell me what can be the issue? In short all wp functions are null. When does wordpress library actually set them? Normally your plugin will run in context of WordPress and you have the same menu of WordPress on left etc. But I need 1 file in my PHP which doesn’t run in context of WordPress but I need to access wordpress functions. It is a simple PHP file which should return just XML no other HTMl etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:02:31+00:00Added an answer on May 26, 2026 at 9:02 am

    The issue is that those variables are not set. So they are NULL.

    If you set them first, they won’t be NULL.

    Try including the wp-load.php file prior making use of these global variables and see if that fits you’re needs.

    See as well:

    • Query to WP db not working on regular PHP page
    • wordpress plugin, access $wpdb on non visible page

    Code:

    //This path assumes your php file is in the template dir, you may need to update the path to these files.
    
    include_once('../../../wp-load.php');
    

    Source: https://stackoverflow.com/a/4035357/835950

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm interested in creating a plugin that does this simple task: Steps 1. User
I'm creating a plugin for wordpress and I need to check if a post
I'm reading some tutorials now about jQuery.. function creating,plugin creation etc. but these tutorials
I'm trying to create a hook in one Wordpress plugin that could be used
I'm creating a Wordpress plugin and, being a newbie in the development on this
I'm creating a wordpress plugin and I was wondering if wordpress has any function
I've created several helper functions which I use when creating templates for Wordpress. An
I am creating one little plugin for WordPress which is about trips. I am
I'm rephrasing my question about creating pages using a Wordpress plugin. Hopefully I do
I came across this problem when I was creating a plugin. I cannot call(access

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.