admin管理员组文章数量:1122833
we created a website where people can post lonely hearts ads. For now we only have a Dutch version available but the idea is to expand to other countries too. It's a great market, and fun to do. But I am stuck on one last problem.
I need ads to be found by their post-id. I am using Geodirectory and when people enter a post-id in the searchbar I want that specific ad to be found.
I added a snippet:
function search_by_post_id($query)
{
if ($query->is_search) {
if (is_numeric($query->query_vars['s'])) {
$query->set('post_type', 'gd_classifieds');
$query->set('post__in', [(int) $query->query_vars['s']]);
$query->set('s', '');
}
}
return $query;
}
add_filter('pre_get_posts', 'search_by_post_id');
Works like a charm, but only on the backend of the website.
Does anyone know how I can make this work on the front-end too? I did set the snippet up to work everywhere, but when I tried to run it ont front-end only it still did not work.
My website is
All help is highly appreciated.
本文标签: How to make search by ID work on frontend
版权声明:本文标题:How to make search by ID work on front-end? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736301585a1931231.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论