admin管理员组文章数量:1122846
I created a plugin that adds content from another post, and places this content next to the original content. I can say, that this content should appear at the bottom of the original post content.
I get post_content
for my additional post, and then call apply_filter('the_content', $custom)
but this code does this not only for my $custom
, but for original content as well! What am I doing wrong?
add_filter( 'the_content', 'custom_content' );
function custom_content( $content ) {
$customPost = get_post( 22 );
remove_filter( 'the_content', 'custom_content' );
$html = $customPost->post_content;
$html = apply_filters( 'the_content', $html );
return $content . $html;
}
I created a plugin that adds content from another post, and places this content next to the original content. I can say, that this content should appear at the bottom of the original post content.
I get post_content
for my additional post, and then call apply_filter('the_content', $custom)
but this code does this not only for my $custom
, but for original content as well! What am I doing wrong?
add_filter( 'the_content', 'custom_content' );
function custom_content( $content ) {
$customPost = get_post( 22 );
remove_filter( 'the_content', 'custom_content' );
$html = $customPost->post_content;
$html = apply_filters( 'the_content', $html );
return $content . $html;
}
Share
Improve this question
edited May 25, 2016 at 20:59
Gabriel
2,24810 gold badges22 silver badges24 bronze badges
asked May 25, 2016 at 17:49
d7p4xd7p4x
1112 bronze badges
4
- When you say "this code does this" can you describe in more detail what happens and what you would prefer to happen? – Andy Macaulay-Brook Commented May 26, 2016 at 7:25
- Yep :) I want to get filtered content of post, wit applied filters,hooks, etc like in normal mode - and place it after content exactly. It should look that I open Post #1, I see render result, and at the end of this post I want include Post #2 content. It works with simple blog posts, but with page builder (for example Avia) it brokes, and put extra tags.. – d7p4x Commented May 26, 2016 at 10:54
- Looks like I should reset everything or something like this, and then render it again..huh – d7p4x Commented May 26, 2016 at 10:55
- Ah if you're content is being messed about by a third party page builder then I wouldn't know, sorry. – Andy Macaulay-Brook Commented May 26, 2016 at 10:57
1 Answer
Reset to default 0the_content will return the whole content of the post and not particular part. If you want to access your particular part, then you can go for shortcode.
For eg, if you have content like this in your post
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's [mycustomtextpart] standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
Then use do_shortcode function to make changes in the [mycustomtextpart] section. Refer.
本文标签: plugin developmentHow to filter content for specific content variable
版权声明:本文标题:plugin development - How to filter content for specific content variable 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305153a1932489.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论