[英]I want to pull latest post and embed other 2 first result posts?
User will search/submit at the same time. 用户将同时搜索/提交。
<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">
This one is the form from wordpress plugin, and its only for a title, and I use that only. 这是来自wordpress插件的表格,仅用于标题,我仅使用它。 When user submits this by title, I have other code which will add post into my wordpress site by bunch of other codes.
当用户按标题提交时,我还有其他代码,这些代码将通过一堆其他代码将帖子添加到我的wordpress网站中。
I already have a query: 我已经有一个查询:
<?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; ?>
So this one basically shows their or the latest post from the wordpress site on same page with search/submit button. 因此,这基本上是通过搜索/提交按钮在同一页面上的wordpress网站上显示他们的最新帖子。
Except this I want to acomplish that to get and embed content of the other site posts found by query from input and embed them after the one above. 除此之外,我想补充一下,以获取并嵌入通过输入从查询中找到的其他网站帖子的内容,并将其嵌入到上述内容之后。
I tried something with new query like: 我尝试了一些新查询,例如:
<?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;
?>
But this $querys = new WP_Query('post_title='.get_the_title().'');
但这
$querys = new WP_Query('post_title='.get_the_title().'');
does not seem to work. 似乎不起作用。 How to do this?
这个怎么做? Plus this second query does not work for links, outside loop, how to solve that too?
再加上第二个查询不适用于链接,外部循环,该如何解决呢?
Have you tried $querys = new WP_Query('post_title="'.get_the_title().'"');
您是否尝试过
$querys = new WP_Query('post_title="'.get_the_title().'"');
this one. 这个。 or may be this one
或者可能是这个
$querys = new WP_Query('s' => get_the_title()); // custom search query
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.