워드프레스 외부에서의 WPDB 사용방법

간혹 외부 API를 이용한 작업을 하거나, 클론 작업등 워드프레스 내부가 아닌 외부 페이지로 만들어야 하는 경우 워드프레스의 DB를 활용할 수 있는 방법에 대해 소개해보고자 합니다.

 

워드프레스 3.4 미만

워드프레스 3.4 미만인 경우는 다음과 같이 합니다.

위의 코드는 워드프레스의 API를 모두 불러오는 방법이긴 하지만 한가지 문제가 있습니다. 플러그인으로 캐쉬를 사용할 경우 원하는 결과를 받아오지 못하는 결과를 초래할 수 있어 아래의 코드처럼 wpdb 객체를 새로 생성해준 후 사용하는 것이 안전합니다.

단, 이렇게 사용하기 위해서 한가지 해주셔야 할 일이 있습니다.

하지 않아도 작동은 이상없습니다만, 보다 안전하게 사용하기 위해 반드시 wp-config.php 내에서 다음과 같은 코드를 한줄 추가해주세요!
OUTSIDE_BLOCK_LOAD 정의부분은 원하시는 문자로 바꾸셔도 되며, 저는 타인이 알 수 없는 문자로 바꾸시는걸 추천해드립니다.

 

워드프레스 3.4 이상

3.4버전 이상에서는 위와 같은 방법으로 wpdb를 사용할 수 없게 되었습니다.
아래와 같이 작성하시면 워드프레스 3.4미만에서 사용한 코드보다는 워드프레스 코어를 더 많이 불러오긴 하지만 전체 코어를 불러오는 것은 아니기때문에 이런 부분은 참고하시어 작업하셔야 합니다.

 

출처

워드프레스를 사용하면서 참 고마운 사람들이 많다라는 것을 많이 느낍니다. 저의 포스트 역시 아래 블로그의 내용을 참고하여 포스트하는 것이오니 참고하여 주시기 바랍니다.

http://www.stormyfrog.com/using-wpdb-outside-wordpress/

lewis hamilton stalked by controversy after mysteriously quitting mercedes cheap nba jerseys testingJacksonville Jaguars Myles Jack, LB, UCLA:Dave Caldwell sure doesn’t sound like a general manager cheap oakleys who might be spooked by a reportedly questionable prognosis on Jack’s surgically repaired knee. Given Jack’s ability to surgically repair a defense burned for an AFC worst 448 points in 2015, why shouldn’t Caldwell take a chance? Like most NFL teams, Jacksonville doesn’t have a player who can range from sideline to sideline and rush off the edge and cover the slot and play deep safety and be a red zone threat as a tailback and return kicks Bell: Is UCLA Myles Jack getting whacked by NFL draft lying season?6.7. The picture’s little better in schools. When we asked teachers about their willingness and ability to tackle homophobic abuse in schools, it was London’s educators who reported the lowest score of any across the nation when it came to even knowing whether they could talk about issues like same sex parents. But it wasn’t to be.Instead of having Berns as an honorary captain in their NFL playoff with the Indianapolis Colts, the Patriots held a moment of silence for the young man who inspired them and many others as he lived with progeria, which causes premature, accelerated wholesale nfl jersyes aging.Berns died Friday evening due to complications from the rare genetic disease, according to the Progeria Research Foundation.He was 17.”I loved Sam Berns and am richer for having known him,” Patriots owner Robert Kraft said. “He was a special cheap jerseys wholesale young man whose inspirational story and positive outlook on life touched my heart.”Advances in kids’ wholesale china jerseys early aging diseaseKraft, one of the most well respected owners in his sport, wasn’t Berns’ only fan. These games have much higher margins than traditional load and play video games. The development of a subscription model for the Call of Duty franchise only adds to the appeal of the company. No pain or swelling after a month and after PT. My husband became seriously ill approx. Gas grills are fueled by liquid oakley outlet propane stored in refillable tanks. Many people prefer gas grilling because it is quick, clean and incredibly easy. Rookie QB Carson Wentz completed 74.4 % of his passes last week, but averaged just 4.7 yards per attempt. It’s promising that he didn’t turn the ball over, but the combination of him not taking chances downfield and play calling that never calls for deep throws is making it far too easy for defenses to bring cheap oakleys outlet their safeties up to stop the run and the short passing game.