简体   繁体   中英

Can't access wordpress database with $wpdb

I have a website that runs Wordpress and I have just started studying php, because I need to retrieve some data from my database for certain purposes.

I'm trying to show the posts of the day in a list, with: 'post_title', 'post_name' and 'post_date' only if 'post_status' is 'publish'. I need to show it in a new page. This new page is loaded in the public_html.

I have tried to follow the rules of $wpdb, but I didn't get anything. Then, I have found that I need to require wp-load to have everything work fine.

The problem is this: when I try to require_once('wp-load.php'); I have a blank page. I tried to echo something before and after it to debug: before everything works, after anything.

The code is really simple:

<?php

    echo "test1";

    require_once('wp-load.php');

    echo "test2";

?>

This is what I get:

test1��).H̳��S�:6

My file and wp-load.php are on the same level.

I have solved adding SHORTINIT before the statement:

    define( 'SHORTINIT', true );
    require('wp-load.php');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM