用户将同时搜索/提交。
<input id="user-submitted-title" name="user-submitted-title" type="text" value="" placeholder="<?php esc_attr_e('Search', 'usp'); ?>"<?php if (usp_check_required('usp_title')) echo $usp_required; ?> class="usp-input">
这是一个来自wordpress插件的表单,它只用于标题,我只使用它。当用户通过标题提交时,我还有其他代码可以通过一堆其他代码将帖子添加到我的wordpress网站。
我已经有了查询:
<?php
include 'wp-load.php';
$args = array(
'post_type' => 'post',
'posts_per_page' => 1
);
$query = new WP_Query($args);
if($query->have_posts()):
$data = '';
while($query->have_posts()):$query->the_post();
$data .= '<h1 style="text-align: center; margin: 0; margin: 0px 0 10px 0px;">'.get_the_title().'</h1>';
$data .= '<div class="description">'.do_shortcode(get_the_content()).'</div>';
endwhile;endif;
echo $data; ?>
所以这个基本上会在同一页面的wordpress网站上用搜索/提交按钮显示他们或者最新的帖子。
除此之外,我想通过输入获取并嵌入查询中找到的其他网站帖子的内容,并将其嵌入上面的内容之后。
我尝试使用新查询,例如:
<?php
include 'wp-load.php';
$querys = new WP_Query('post_title='.get_the_title().'');
if($querys->have_posts()) : while($querys->have_posts()) : $querys->the_post();
if (has_post_thumbnail()) {
?>
<a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a>
<?php
}
?>
<h2><a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<?php
the_excerpt(); // or the_content(); for full post content
endwhile;endif;
?>
但这$querys = new WP_Query('post_title='.get_the_title().'');
似乎不起作用。
这该怎么做?
此外,第二个查询不适用于链接,外部循环,如何解决?
答案 0 :(得分:0)
你试过吗?
$querys = new WP_Query('post_title="'.get_the_title().'"');
这一个。
或者可能是这个
$querys = new WP_Query('s' => get_the_title()); // custom search query