Created
October 29, 2013 16:07
-
-
Save nciske/7217586 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/* | |
== Requirements == | |
http://wordpress.org/plugins/json-api/ on the source domain. | |
*/ | |
/* | |
== Usage == | |
[json_include url ="http://domain.com/url"]Enter fallback content here.[/json_include] | |
*/ | |
/* | |
== Shortcode == | |
Using page caching or caching the result in a transient for 24 hours | |
is probably a good idea from a performance perspective. | |
*/ | |
add_shortcode( 'json_include', 'json_include_sc' ); | |
function json_include_sc( $atts, $content ){ | |
extract( shortcode_atts( array( | |
'url' => '', | |
), $atts, 'json_include' ) ); | |
if( !$url ) return $content;; | |
$url = add_query_arg( 'json','1', $url ); | |
$response = wp_remote_get( $url ); | |
if( !$response ) return $content; | |
$post = json_decode( $response['body'] ); | |
//echo '<pre>'. print_r($post,1) . '</pre>'; | |
if( isset( $post->page->content ) ) { | |
return $post->page->content; | |
}else{ | |
return $content; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Written for:
http://www.quora.com/WordPress/How-can-I-get-a-wordpress-page-content-from-another-wordpress-instance-on-a-separate-domain