There's a better way to do this, if your WP and MODX installs are on the same server, so I thought it might be useful to post it here.
Including MODX Revo chunks in Wordpress Templates
First, add the following code to the functions.php file of your Wordpress theme. Be sure to change "/BASE/PATH/TO/YOUR/MODX/INSTALL/PLEASE/REPLACE/" to your actual MODX base path.
define('MODX_API_MODE', true);
require_once '/BASE/PATH/TO/YOUR/MODX/INSTALL/PLEASE/REPLACE/index.php';
function get_modx_chunk($chunkName, $properties = array(), $resourceId = 0, $context = 'web') {
$modx = new modX();
/*Initialize the selected context*/
$modx->initialize($context);
$modx->getService('error','error.modError', '', '');
/*if resourceId is 0, switch to whatever is the site start*/
if($resourceId == 0) {
$resourceId = $modx->getOption('site_start', null, 1);
}
/*process the chunk as it would appear on the selected resource*/
$resource = $modx->getObject('modResource',$resourceId);
$modx->resource = $resource;
$modx->resourceIdentifier = $resourceId;
$output = $modx->getChunk($chunkName, $properties);
/* get the max iterations tags are processed before processing is terminated */
$maxIterations= (integer) $modx->getOption('parser_max_iterations', null, 10);
/* parse all cacheable tags first */
$modx->getParser()->processElementTags('', $output, false, false, '[[', ']]', array(), $maxIterations);
/* parse all non-cacheable and remove unprocessed tags */
$modx->getParser()->processElementTags('', $output, true, true, '[[', ']]', array(), $maxIterations);
return $output;
}
This function gets a chunk from MODX and parses any uncached tags in the chunk.
Then put code like this where you want a MODX chunk to appear in your Wordpress theme, replacing "my-chunk-name" with your chunk name.
<?php
echo(get_modx_chunk('my-chunk-name'));
?>
You can pass an optional array of properties into the chunk using the second argument.
By default, the chunk will be rendered as it would appear on the site_start resource (i.e. the homepage). If you want it to render as if it were in some other resource, pass the ID of that resource in the third argument.
By default, the chunk will be rendered in the "web" context. If you want to use another context, pass that as the fourth argument. Example:
<?php
echo(get_modx_chunk('my-chunk-name', array('my-property' => 'value'), 23, 'my-context'));
?>