Issue
I would like to modify a posts content with the "the_content" filter. Inside this filter I would like to load another posts content.
This is my code:
add_filter( 'the_content', 'my_content_filter' );
function my_content_filter( $content ){
if ( !is_singular( 'my-custom-post-type' ) ){
return $content;
}
ob_start();
echo '<p>SOME HTML BEFORE THE CONTENT</p>';
echo $content;
echo '<p>SOME HTML AFTER THE CONTENT</p>';
$module = get_post( 12345 ); // load specific post
echo apply_filters( 'the_content', $module->post_content );
echo '<p>SOME MORE HTML</p>';
$html = ob_get_contents();
ob_end_clean();
return $html;
}
Sadly this creates a 500 Internal Server Error. I guess because I created an endless loop. Do you have any idea how to get the formatted content of another post inside the "the_content" filter?
Thanks :-) Jan
EDIT
A bit more details: I created a custom post type called "sidebars" where I edit the content with a page builder. I would like to add this sidebars with PHP.
Solution
SOLUTION
With the "Elementor" page builder you can do this:
add_filter( 'the_content', 'my_content_filter' );
function my_content_filter( $content ){
if ( !is_singular( 'my-custom-post-type' ) ){
return $content;
}
ob_start();
echo '<p>SOME HTML BEFORE THE CONTENT</p>';
echo $content;
echo '<p>SOME HTML AFTER THE CONTENT</p>';
$elementor = \Elementor\Plugin::instance();
echo $elementor->frontend->get_builder_content( 12345 );
echo '<p>SOME MORE HTML</p>';
$html = ob_get_contents();
ob_end_clean();
return $html;
}
Answered By - Jan K
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.