Get the excerpt by page ID from another blog in a wordpress multisite?
-
06-11-2019 - |
Question
I am trying to get the first paragraph on a page where page ID=2 and blog ID=1. I want to display this paragraph on a page in blog id=2. I have added the following code to the template page.
//gets active blog
global $blog_id;
switch_to_blog(1);
$pageid = 2; //author page
$post = get_post( $pageid );
$excerpt = get_the_excerpt( $pageid );
//$content = apply_filters('the_content', $post->post_content); //filters just the post content
echo "<div id='about-alandracl'>";
echo $excerpt;
//echo $content;
echo "</div>";
restore_current_blog();
I have the following in the functions.php file of each theme:
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 206 );
This is the page where I am grabbing the content from: http://alandracl.com/author/ This is the page I want to display the first paragraph (without the image) on: http://alandracl.com/the-sussex-deal/ (under the about section on this page).
Thank you for your help in advance.
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange