如何查询帖子仅使用&#34; <img“in =”“its =”“content?=”“wordpress =”“

时间:2016-09-15 09:55:11

标签: wordpress

=”“

我正在处理我的个人博客主题,我想列出我的所有&#34;图像帖子&#34;(在其中有图像)到一个页面,所以我建立了一个页面模板,但不要&# 39;知道如何使WordPress仅查询带有图像的帖子。

我知道如何使用精选图片查询帖子,但我的博客太旧了,很多帖子都没有精选图片。因此,如果我可以搜索和查询帖子&#34;

有没有办法制作自定义查询来获取所有帖子

1 个答案:

答案 0 :(得分:0)

现在我找到了解决方案,只需搜索“ img”标签就可以完美地完成工作,查询就这样

<?php
// set up or arguments for our custom query
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$query_args = array(
'post_type' => 'post',
's' => '<img',
'posts_per_page' => 9,
'paged' => $paged
);
// create a new instance of WP_Query
$the_query = new WP_Query( $query_args );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); // run the loop 
?>