X
X
xlo2402021-10-31 13:37:25
WordPress
xlo240, 2021-10-31 13:37:25

How to connect to the database from a file in the root of the site?

You need to connect to the database from a file in the root of the site. But apparently WordPress doesn't see the wpdb class from the root. Only from template folders. How to solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Brumer, 2021-10-31
@xlo240

<?php
require_once __DIR__ .'/wp-load.php';
global $wpdb;
$sql=$wpdb->prepare("SELECT domain, path FROM $wpdb->blogs WHERE public=%s AND archived=%s AND deleted=%s",array(1,0,0));
$blogs=$wpdb->get_results($sql);
var_dump($blogs);
...

spoiler

617e8c2439a92742222714.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question