1

I have created a page by using add_submenu_page:

add_submenu_page(
    "pharma-plugin", // parent slug
    "All Trade Name", // page title
    "All Trade Name", // menu title
    "manage_options", // capability = user_level access
    "all-trade-name", // menu slug
    "all_trade_name" // callback function
);

My page id is ?page=all-trade-name. I want to get data form this page query in custom database table datas in wordpress search.php page . My database table name is: tbl_trade.

<input placeholder="Enter product name" type="search" name="s" title="Search" value="">

This input field is my WordPress search input field.

I created functions in functions.php

function searchfilter($query) {

if ($query->is_search && !is_admin() ) {
    $query->set('page',array('all-trade-name'));
}

return $query;
}

 add_filter('pre_get_posts','searchfilter');

But it won't works.

  • This is a fundamental misunderstanding of how search works in WordPress. it doesn't make any sense to be able to search an admin page. What you're actual problem is is that you want to search a custom database table. The admin page is completely irrelevant. That's just a UI for managing the data. You're going to need to: Create your own search form with a name other than s (you can't use WordPress'), your own code/algorithm for doing the search, and then your own code for displaying the results. WordPress isn't really going to be able to help with any of that. You need to do it yourself. – Jacob Peattie May 1 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.