Return to Snippet

Revision: 61319
at December 5, 2012 22:05 by Zayac


Updated Code
<?php

define('WP_DEBUG', false);

//fake funcs
function is_multisite() {return true;}
function apply_filters($tag, $value) { return $value; }
function wp_load_translations_early() {}
function __($text) { return $text; }
function wp_debug_backtrace_summary( $ignore_class, $skip_frames, $pretty) { return array(); }
//

$doc_root = $_SERVER['DOCUMENT_ROOT'];
require $doc_root . '/db-config.php';
require $doc_root . '/wp-includes/wp-db.php';

//Oh, Yeah!
$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);

?>

Revision: 61318
at December 5, 2012 22:00 by Zayac


Updated Code
<?php

define('WP_DEBUG', false);

function is_multisite() {return true;}
function apply_filters($tag, $value) { return $value; }
function wp_load_translations_early() {}
function __($text) { return $text; }
function wp_debug_backtrace_summary( $ignore_class, $skip_frames, $pretty ) { return array(); }

$doc_root = $_SERVER['DOCUMENT_ROOT'];
require $doc_root . '/db-config.php';
require $doc_root . '/wp-includes/wp-db.php';

//Oh, yeah!
$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);

?>

Revision: 61317
at December 5, 2012 21:59 by Zayac


Updated Code
<?php

define('WP_DEBUG', false);

function is_multisite() {return true;}
function apply_filters($tag, $value) { return $value; }
function wp_load_translations_early() {}
function __($text) { return $text; }
function wp_debug_backtrace_summary( $ignore_class, $skip_frames, $pretty ) { return array(); }

$doc_root = $_SERVER['DOCUMENT_ROOT'];
require $doc_root . '/db-config.php';
require $doc_root . '/wp-includes/wp-db.php';

$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);

print_r($wpdb->get_results('SELECT id, title, link FROM z_publications', ARRAY_A));

?>

Revision: 61316
at December 5, 2012 21:43 by Zayac


Initial Code
<?php

define('WP_DEBUG', false);

function is_multisite() {return true;}
function apply_filters($tag, $value) { return $value; }

$doc_root = $_SERVER['DOCUMENT_ROOT'];
require $doc_root . '/db-config.php';
require $doc_root . '/wp-includes/wp-db.php';

$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);

print_r($wpdb->get_results('SELECT id, title, link FROM z_publications', ARRAY_A));

?>

Initial URL


Initial Description
So, you define a couple of fake funcs and require WP database config, after this you can require wp-db.php, create new wpdb and use it independency of WP for your ajax actions.

Initial Title
wordpress include wpdb only (wpdb for ajax)

Initial Tags
ajax, wordpress

Initial Language
PHP