$_SERVER['DOCUMENT_ROOT']; is not going to include secondsite. So all the files, including wp-config.php with the database details, are coming from the root public directory.
To get the current directory, including subdirectories, use any of these:
getcwd();
dirname(__FILE__);
basename(__DIR__);
But if your file is in a deeper folder, you can’t find the secondsite directory without specifying it (or scanning directories to find a WordPress installation). So you need to manually specify it like so:
$path = $_SERVER['DOCUMENT_ROOT'] . '/secondsite';
But your problem is that you’re doing AJAX wrong. You shouldn’t be sending AJAX requests directly to a file in your plugin. You should be using the AJAX hooks or adding a custom endpoint to the REST API.
Related Posts:
- How to delete all records from or empty a custom database table?
- dbDelta only creates the last table
- Is their any way to Extend WPDB class and Overwrite the Default Query Function
- Stackoverflow type of badge plugin giving warnings in WordPress 3.5
- Missing argument 2 for wpdb::prepare() Issue
- ob_end_flush error when using wpdb in plugin
- $wpdb->get_results() does not fetch results with unicode ‘WHERE’ clause
- post_content getting cut off on blank space on $wpdb->update
- Why am i getting this error? WordPress database error: [Query was empty]
- Inserting large amounts of data into a custom table during plugin install
- plugin ajax to external php file always return null
- When to call add_filter
- Doubt using $wpbd->get_col for a single column
- Access WordPress database outside of WordPress
- Correct way to perform non-cacheable DB query
- Help With MySQL to WPDB Query Conversion
- Creating mySQL procedure with $wpdb
- Problem with creating tables for Plugin
- Change commission_status paid when withdraw_status vendor is completed
- $wpdb->get_row returns column name instead of column value
- Create a table with wordpress plugin boilerplate
- plugin code is pulling information from database in one instance and not in other. What is wrong?
- Object method calling for global $wpdb in header.php
- Using wpdb without loading all plug-ins via wp-load.php
- after wordpress update to 3.5+ i get many errors in plugin wpdb::prepare()
- How to insert multiple postmeta values with one query?
- Cannot get wpdb data (Error in a simple fuction) [closed]
- WPDB: Update table
- Issue running db create table query from static method
- $wpdb update query in plugin only updating one column
- Mowing site to another domain in simplest way
- Store plugin page content in wp_options?
- Displaying data from another database
- Using $wpdb in a plugin, what sort of data does it return?
- How to access the WordPress DB from a plugin file
- WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version [closed]
- Linked pages from plugin on front can’t see $wpdb
- Need help creating asynchronous data scraper in WordPress
- ob_end_flush(): failed to send buffer of zlib output compression (0) in external php
- How to fetch WordPress database values in JavaScript widget
- $wpdb->delete not working for me
- any word search WordPress
- How to securely controlling data without keeping it in postmeta?
- Using id to show item
- No result after wpdb->insert
- How to fix slow comment query?
- Write mysql credentials in plugin
- Action hook “wp_insert_post” works but not for last imported post
- Proper way to trigger a MySQL query via link in a plugin
- get_var result empty for query of custom table in plugin admin
- Making plugin to use different table prefix cause permission problem
- Is it safe to increase/alter the size of the wp_post.guid column from VARCHAR(255) to VARCHAR(2048)?
- Get all the related data from WordPress DB
- How to dispaly post informations (such as titles) in an admin plugin menu page?
- FATAL ERROR: WP complains about redeclaration [closed]
- How to check record is exist or not in WordPress CRUD Operation with $wpdb
- wp db request without refreshing the page
- WooCommerce search products between price range using WP_Query
- Stop WordPress processing Javascript as text
- Full list of registered scripts or styles, but from an admin options page
- Why is the ‘Gutenberg’ Plugin generating an ‘Inconsistent File Permissions’ error when other Plugins, with the same permissions, do not?
- Using wordpress translations strings in plugin
- how to insert a HTML form into a javascript popup?
- get specific value of a array | PHP
- Displaying content based on drop-down menu selection sitewide
- sending different email notification while registration based on user role
- How to save comment name email url fields?
- Best practices for user registration with WordPress from an MVC background
- How to get a notification when the plugin is installed?
- WordPress Post HTML after Posting
- How to append new form elements in “Add New” form of Users in WordPress admin panel?
- Settings options not showing up on Sub Menu page in WordPress plugin
- Using Amazon Book Gallery Plugins in WordPress [closed]
- Custom Meta box change size
- The Build menu theme is frozen with the wordpress theme
- How to add label/badge on bookable product based on their booking status
- Does anyone know why my SEO and title become one?
- WordPress PWA with Form
- Help to create function that changes name in the certificate of the sensei lms
- How achive serving multiple concurrent Ajax / Rest calls in plugin?
- After migrating with duplicator all scripts are still tied to old CDN
- How to prevent redoing get_posts queries and make results available to other scripts?
- Optimized PHP & WordPress settings for speed/performance?
- How to add php plugin code in theme
- ound this in Where to edit Custom Content fields to optional if there is no plug in?
- How to add a meaningful link in plugin admin panel?
- How to set up php,javascript and css to allow for our finished product to be displayed within a page?
- jQuery loaded in wrong order for non-admin page views only
- Widget redirecting to home page
- Advanced Custom Fields Plugin – not displaying images
- Creating Features List in WordPress Post
- why i cannot see some plugins while they are enabled on network admin page?
- wordpress Search function is not working
- WooCommerce Email Customization
- SSL not working for checkout
- Plugin LDAP Authentication 2 In stallation ploblem
- How to change post status to draft in Gutenberg?
- Filter custom post type returned from REST api
- Is it a good idea to restrict the REST API
- How to configure redis object cache for multiple sites in the same server without errors