我正在编写一个小插件,它可以创建custom post 类型
我创建了一个过滤器copies the content 把这样一个职位换成另一个职位。
因此,我遍历了所有自定义帖子。每一个我都有一个target_type
它的字段值。
将此值与实际值进行比较post_type
已查看帖子的。如果相同,则会追加内容。
My problem is 自定义帖子内容中使用的短代码应在目标帖子的上下文中呈现。
例如:我在自定义帖子中使用了一个短代码,它只返回get_the_title();
在目标帖子中,显示自定义帖子的标题。
事实上,我希望自定义帖子只是作为稍后呈现内容的容器。
哇,这对我来说真的很难解释。
我希望有人能理解我的问题并能帮助我。
提前感谢您!
以下是过滤器代码:
add_filter(\'the_content\', \'copy_content\');
function copy_content( $content )
{
$post_type = get_post_type();
$args = array(
\'post_type\' => \'custom\',
\'post_status\' => \'publish\',
\'posts_per_page\' => -1
);
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
while($post_query->have_posts() ) {
$post_query->the_post();
$target_type = get_post_meta(get_the_ID(), "target_type")[0];
if($target_type == $post_type){
return $content . get_the_content();
}
}
}
wp_reset_postdata();
return $content;
}