WordPress的get_posts按标题 [英] WordPress get_posts by title like
本文介绍了WordPress的get_posts按标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为WordPress创建一个小的搜索功能. AJAX调用应获取标题类似于%quote%
的所有帖子.
I am trying to create a small search-function for WordPress. An AJAX call should get all posts where the title is like %quote%
.
是否有可能在get_posts()
函数内部使这种情况发生?
Is there a possibility to make this happen inside the get_posts()
function?
别误会我的意思. Ajax正常工作.我在functions.php中具有ajax函数,并且收到了帖子.只是找不到标题的地方"部分,而我找不到解决方案.
Don't get me wrong. The ajax works fine. I have the ajax function in my functions.php and I receive the posts. It's just the "where title like" part where I couldn't find a solution.
推荐答案
否,但是您可以创建一个自定义循环.
No, but you can create a custom loop.
$args = array('s' => 'keyword');
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
//whatever you want to do with each post
}
} else {
// no posts found
}
这篇关于WordPress的get_posts按标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文