Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrebian/c7cb37e219a5131a7fe7 to your computer and use it in GitHub Desktop.
Save andrebian/c7cb37e219a5131a7fe7 to your computer and use it in GitHub Desktop.
Buscando post (ou qualquer outra coisa) do wordpress dentro do CakePHP
<?php
// app/Config/database.php
public $wordpress = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => 'root',
'database' => 'wordpress',
'prefix' => 'wp_',
'encoding' => 'utf8'
);
// ----------------------------- //
// app/Model/WordPressModel.php
App::uses('AppModel', 'Model');
class WordPressModel extends AppModel {
public $useDbConfig = 'wordpress';
public $useTable = 'posts';
}
// ----------------------------- //
// app/Controller/SeuController.php
public function algumAction() {
$lastPost = $this->WordPressModel->find('first', array(
'conditions' => array(
'WordPressModel.post_type' => 'post',
'WordPressModel.post_status' => 'publish'
),
'order' => array(
'WordPressModel.ID' => 'DESC'
))
);
die(debug($lastPost));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment