First of all you probably created an isolated file that is not under the umbrella of WP files. That’s why you are not getting $wpdb. I guess you may not following the general rules/conventions of theme development. my question is now how are you accessing the file?
whatever, if you include the wp_config.php in your file, you will get the $wpdb in your file.
considering in a directory under themes directory, here is how you include/require the file
require_once ('../../../wp-config.php');
you may need to alter the path based on your system.
Related Posts:
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- phpMyAdmin – Error > Incorrect format parameter?
- Why is my database import losing text widget data?
- Does dbDelta delete columns as well?
- Are There Any Plans for WordPress to Support Databases Other Than MySQL?
- Insert data in database using form
- how can get database name in wordpress?
- The ideal place for storing persistent PHP objects
- Why term_id is not indexed in wp_term_taxonomy table?
- Presentation vs Content in WP DB-Tables
- Importing users from one database to another and saving passwords
- Split WP install between 2 databases?
- Inserting Post Meta From SQL
- Saving Metadata from the Gutenberg Editor Sidebar to the Database
- Accessing two databases
- Is altering a default WordPress database table update safe?
- Copy customizer options to child theme
- How to use user table of a different database for WordPress users?
- How to prevent WordPress from retrieving data for the last 10 posts in the database?
- error establishing a database connection
- Get data from database using $WPDB
- Getting all the users who have author privilege
- For WordPress is there content in the database which I can safely ignore?
- WordPress mysql table double prefixes
- SQL Query to Update Admin Email
- Transient feeds and caching error
- get_tags() return an empty array after added tags with wp_insert_term()
- Is it a bad idea to write audit/access/transaction log information directly to the filesystem?
- Why do mass updates to post_content shows in front end, but not in edit screen?
- How to disable (get rid of) home page main loop entirely?
- Export / import WordPress database
- WordPress choose wrong database
- Sync user meta data to a second database
- Is it safe to delete unnecessary user metadata?
- WordPress Relational Database
- WordPress Database Huge wp_usermeta Table
- wp-cli search is returning ‘search’ is not a registered subcommand of ‘db’
- Switching Databases in LocalHost
- How to get membershiplevel from WordPress Database?
- cache specific data?
- wp_insert_post causing There was an error connecting to the database: Access denied for user ‘root’@’localhost’ (using password: NO)
- How to update the values when the featured image has changed?
- Does WordPress $wpdb functions wait when table is locked?
- Copying database tables to new database
- Duplicating Complete WordPress Install for Development and then Redeployment?
- Importing 10 Years of Media into the WP Database
- I have a 1300 line excel spreadsheet that needs to get into a wordpress site ASAP – Looking for ideas
- 2 WordPress sites with 2 databases but sharing the same users
- How to combine multiple wp_insert_post into one in order to gain better performance
- Insert Query not working in the form
- Two prefixes in database? Which one is valid?
- Enter user registration information in the database
- connecting to DB from custom php file
- Problem in using wpdb
- Make changes of wp-db.php file persistent against updates
- pull data from a remote wordpress database
- Create database on installation
- Importer fails to import every post
- Users table missing from Database [closed]
- Clear Terms from Taxonomy for Specific Post IDs?
- Options on how to Display member specific data from a MS SQL database
- Unkown meta_value in ACF
- Buddypress avatar image in database [closed]
- WordPress security [closed]
- How to split the WordPress database?
- wp_insert_user not creating account correctly when ID is manually set
- Installing local to live WP into subdirectory
- WordPress SQL – How to Check for Category?
- Getting WordPress to work inside a rails 3 application
- Advantages of dbDelta
- Only allow user to access a link once a year, based on their joining date
- MSQL database wp_postmeta has meta key tve_revision
- Occasional Error Establishing a Database Connection
- Display user data in numbered list
- Removing old_slug and old_date from WordPress Database
- Help with $wpdb on custom code
- “BS_” rows in postmeta table
- Migrating meta_key and meta_value from old theme to new one
- How do I change several broken URLs in a several wordpress databases in the fastest way?
- Optimize WP site for millions of posts
- I Want a More Concice Form of Data than an Array
- Duplicate database to roll back theme & content changes
- WordPress Migration – Issue with admin panel changes
- Select data from foreach loop and send it to wordpress database
- mySQL database size large, but tables size less
- Error establishing database connection error during first WordPress run
- How To connect to the same WordPress database with different database user
- How much post meta data is too much?
- I have include wp-config, should I add global $wpdb also?
- Localize strings from db
- Can’t Install WordPress (local) Failed to open file wp-includes/wp-db.php
- version control for wordpress? (wordpress folder and database at same time)
- Redirect Issue: WordPress database
- Install WordPress with SQL database
- Creating Job Tickets
- Best db table structure for users with many records
- How to stop WordPress from using utf8mb4_unicode_ci collation
- Many images in wp-content/uploads folder that are not in Media Library
- Order of search results based off of a backend custom field and also in alpha order
- How to find fresh (last modified) and sql backup?