반응형
Word press oop wpdb in class
OOP PHP는 처음이라서 커스텀클래스에서 $wpdb(WORDPRESS) 오브젝트를 사용하려고 하는데 방법을 모르겠어요.$wpdb로 기본 작업을 구현하려고 할 때마다 실패합니다.get_results(), ...와 같은 기본적인 것이 필요합니다.그럼 어떻게 하면 좋을까요?
global $wpdb;
$my_custom_table = $wpdb->prefix . "table_name";
$table_content = $wpdb->get_results("SELECT * FROM ".$my_custom_table);
이렇게 수업시간에 넣었어요.
Class MyClass{
public function table_results(){
//put in here
return $this->table_content;
}
}
그 수업은 내가 쉽게 부를 수 있도록 별도의 파일로 해야 한다.
이거 드셔보세요.
<?php
class MyClass {
private $wpdb;
public function __construct()
{
global $wpdb;
$this->wpdb = $wpdb;
}
public function table_results(){
$my_custom_table = $this->wpdb->prefix . "table_name";
$table_content = $this->wpdb->get_results("SELECT * FROM $my_custom_table");
return $table_content;
}
}
언급URL : https://stackoverflow.com/questions/31096669/wordpress-oop-wpdb-in-class
반응형
'programing' 카테고리의 다른 글
XMLHttpRequest(Ajax) 오류 (0) | 2023.03.22 |
---|---|
패키지 내 프록시.json은 가져오기 요청에 영향을 주지 않습니다. (0) | 2023.03.22 |
워드프레스에서 모든 카테고리를 표시하는 방법 (0) | 2023.03.22 |
React.js - 기본 프로펠이 null과 함께 사용되지 않습니다. (0) | 2023.03.22 |
swing 어플리케이션을 사용한 스프링부트 설정 방법 (0) | 2023.03.22 |