首页 > 解决方案 > 过滤帖子内容(Wordpress)

问题描述

我参与了 Wordpress 下的一个网络项目,如果您能帮助我解决以下问题,我需要。在网络上的每个帖子中都有一个嵌入视频(通常来自 Youtube),通过以下短代码:

[video src="https://www.youtube.com/watch?v=ZYZxmYP7QOo"]

在显示这些帖子的页面中,在视频下方,有来自网站不同用户的评论、视频标题、作者社交网络的链接等......)。

此外,我创建了一个页面,登录网络的用户可以看到他上传的完整视频列表。现在的问题是,当这个页面显示用户信息时,帖子的所有内容也会显示出来(包括,pe,评论)。我希望只显示视频及其标题(没有评论或任何其他信息)。到现在写的代码如下:

// tipo POSTS
$the_args['post_type']='post';
$the_query = new WP_Query($the_args);
?>
<?php if ($the_query-> have_posts ()) :?>
<h2>posts</h2>
<ul>
    <?php while ($the_query-> have_posts ()) : $the_query-> the_post();
      the_content();
    php endwhile; ?>
</ul>
<?php endif; ?>

问题:

我该如何过滤the content()?我知道它应该使用该功能add_filter (),但我不知道执行此操作的指定代码。

问候

标签: wordpresspost

解决方案


您可以为视频创建一个自定义字段,而不是使用简码,然后像下面这样过滤输出

   <?php while ($the_query-> have_posts ()) : $the_query-> the_post();
      the_title();
      the_field('video');
    php endwhile; ?>

推荐阅读