From MODx Wiki
Jump to: navigation, search
 API Function Definition: 
> 0.6.0
Return Values
Success: The document
Fail: boolean false
Data Type 
Object Hierarchy 
array getDocument(int $id[, string $fields[, int $published[, int $deleted]]]);

Retrieves a document from the database given the id. By default, this function searches for published documents that are not deleted. The defaults can be overridden by the 3rd and 4th parameters of the function.


// Retrieve document 6 regardless of publish state.
$doc = $modx->getDocument(6, '*', 1); // Search published first.
if (empty($doc))
	$doc = $modx->getDocument(6, '*', 0); // Un-published next

Related Functions

Source Code

File: manager/includes/document.parser.class.inc.php
Line: 1429

function getDocument($id= 0, $fields= "*", $published= 1, $deleted= 0) {
        if ($id == 0) {
            return false;
        } else {
            $tmpArr[]= $id;
            $docs= $this->getDocuments($tmpArr, $published, $deleted, $fields, "", "", "", 1);
            if ($docs != false) {
                return $docs[0];
            } else {
                return false;


  • This function is nothing more than a wrapper for the getDocuments API Function.
  • It is currently not possible to search for all documents regardless of publish or deletion state.
Personal tools