Last active
November 2, 2015 21:00
-
-
Save andrebian/c7cb37e219a5131a7fe7 to your computer and use it in GitHub Desktop.
Buscando post (ou qualquer outra coisa) do wordpress dentro do CakePHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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