我对ElasticPress.
在成功安装和连接WordPress和ElasticPress并为数百篇文章编制索引以进行测试之后,我发现一切正常,直到我尝试创建自定义WP_Query
. 结果页只有标题行,但未显示帖子内容。在search.php
这是我写的
$wp_query = new WP_Query( array(
\'ep_integrate\' => true,
\'post_type\' => \'post\',
\'posts_per_page\' => 20,
\'tax_query\' => array(
array(
\'taxonomy\' => \'category\',
\'terms\' => array( get_query_var(\'cat\') ),
\'field\' => \'term_id\',
),
),
) );
if ( $wp_query->have_posts() ) {
// Start the loop.
while ( $wp_query->have_posts() ) : $wp_query->the_post();
/**
* Run the loop for the search to output the results.
* If you want to overload this in a child theme then include a file
* called content-search.php and that will be used instead.
*/
get_template_part(\'template-parts/content\', \'search\');
// End the loop.
endwhile;
// Previous/next page navigation.
the_posts_pagination(array(
\'prev_text\' => __(\'Previous page\', \'twentysixteen\'),
\'next_text\' => __(\'Next page\', \'twentysixteen\'),
\'before_page_number\' => \'<span class="meta-nav screen-reader-text">\' . __(\'Page\', \'twentysixteen\') . \' </span>\',
));
wp_reset_postdata();
// If no content, include the "No posts found" template.
} else {
get_template_part(\'template-parts/content\', \'none\');
}
不幸的是,我没有找到任何关于如何在构建自定义查询时正确使用ElasticPress的信息。所有教程都很简单,展示了如何编写新的
WP_Query
结果是在没有任何其他编程的情况下生成的。
全局post变量不是空的,页面上仍然缺少post内容。WordPress为4.6.1,ElasticPress为2.1.2。
有人能告诉我创建自定义查询和显示结果的正确方法吗。我知道ES,但我几乎是WP的初学者。