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