wordpress - 过滤帖子内容(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 ()
,但我不知道执行此操作的指定代码。
问候
解决方案
您可以为视频创建一个自定义字段,而不是使用简码,然后像下面这样过滤输出
<?php while ($the_query-> have_posts ()) : $the_query-> the_post();
the_title();
the_field('video');
php endwhile; ?>
推荐阅读
- java - 您如何将 2020-1-7(无尾随零)和 1/1/2020 格式的文本解析为 LocalDate?
- javascript - OPTIONS net::ERR_CONNECTION_REFUSED + 同源策略不允许读取远程资源(原因:CORS 请求未成功)
- python - 在 Python 中生成随机的 6 位 ID
- json - 单个空格/换行符/回车符/水平选项卡是否属于 json?
- c# - WCF 不活动超时
- node.js - 使用 Node.js 计算半径内的附近用户?
- javascript - 如何在数据表jquery中添加列过滤,除了操作列
- ruby-on-rails - 将数据从 RoR 中的其他两个表添加到中间表中
- java - 有没有办法在从 PostgreSQL 数据库表中获取的给定日期时间从 spring boot 自动调用函数?
- google-bigquery - 何时在 BigQuery 中使用分区