문제

I have a wordpress blog. I created a db table which stores dictionary information and I want to publish this data from a URL . (For ex: "myblogaddress.com/mytest.php")

I have been researching for 2 days but nothing works I tried.

In my page; I use the php code shown in blow.

<?php
global $wpdb;
   $words = $wpdb->get_results("SELECT * FROM $wpdb->words")

echo $words[0]->ENG;


?>

I wonder that; - Which directory does my php page to be into ? - What I need to do (other config, permission etc.) to do what I want.

Regards.

도움이 되었습니까?

해결책

If you're loading it from a standalone PHP file (ie not from within your WordPress theme), you'll have to call wp-load.php to initialise the WordPress variables (including $wpdb). Have a look at this answer, including the comment about only needing wp-load.php.

I'd consider using a relative path (what that would be would depend on where you put your page relative to WordPress) rather than using $_SERVER['DOCUMENT_ROOT'];, but that's just a personal preference.

EDIT

Rereading after seeing your comment, I've just realised $wpdb->words probably won't exist. Try

$words = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "words")

instead. That'll generate the table name correctly as wp_words. Of course, you'll need to populate it the same way.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top