Here’s the right code I made a mistake with s param
function custom_search_query($query) {
if (!is_admin() && $query->is_main_query() && $query->is_search()) {
$search_query = get_search_query(); // Retrieve the search query
$api_url="https://api.adenwalla.in/api/search/data";
$args = array(
'body' => json_encode(array('query' => $search_query)),
'headers' => array('Content-Type' => 'application/json'),
'timeout' => 60
);
$response = wp_remote_post($api_url, $args);
$body = wp_remote_retrieve_body($response);
$results = json_decode($body, true);
if (isset($results['ids']) && is_array($results['ids'])) {
$query->set('post__in', $results['ids']);
$query->set('orderby', 'post__in');
$query->set('posts_per_page', -1);
$query->set('s', '');
}
}
}
add_action('pre_get_posts', 'custom_search_query');
Related Posts:
- Custom Shipping method not showing in checkout
- Create or Update thousands of woocommerce products via PHP
- Creating a Callback URL for WordPress Woocommerce to update Order Status
- Redirect to another page using contact form 7? [closed]
- Change Woo Custom Endpoint Titles from a Plugin
- Woocommerce list variations that are added already to cart in Single Product
- Change pricing in Woocommerce based on Category and Product [closed]
- Problem with conditional woocommerce custom checkout field
- Unable to show 4 products in a row
- Woocommerce attatch files and custom input meta to cart items and then to order
- What are the differences between WPINC and ABSPATH?
- Problems with autoloading classes via sp_autoload_register / maybe interfering WP-specific autoloader
- How to remove duplicate sub-menu name for top level menu items in a plugin?
- Customizing subject in comment notification e-mails
- category_name not working (not showing up in sql query debug)
- Using require_once in a Plugin?
- How can I make my custom shortcode work in a Custom HTML Widget?
- How to Loop Plugin Option Field Set?
- WP WC CLI – WooCommerce setup store with wp-cli [closed]
- Making plugin unique to not conflict with plugins with the same name
- How to find out if option exists but is empty?
- Update Multiple Post Meta for the Same Post In One call?
- How to pass JavaScript variable to PHP in wordpress widget?
- Unable to add admin notice on plugin activation
- How To Ignore a Filter On Applying Filter the Content In a Function
- Add multiple attributes to product from php
- jQuery function didn’t work in my plugin
- Is it possible to set up multistore in Woocommerce? [closed]
- Sanitizing, Validating and Escaping in WordPress (Plugin)
- Escape when echoed
- Scope for PHP Variables Assigned in functions.php or a plugin
- Make specific products accessible only to a user role in WooCommerce
- How to remove the woocommerce_checkout_process action hook in woocommerce if particular project in cart [closed]
- Plugin exceeds memory limit
- How to get subscription key or id using Woocommerce Subscriptions [closed]
- Write to / remove from default .htaccess file from plugin?
- Update Option Error: Notice: Undefined index
- How can I display a contact form for out of stock products in WooCommerce?
- Plugin Development sqlite or WordPress’ database
- How to cancel WordPress’ action/filter when using OOP with anonymous callback
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- How to trigger $_GET request within admin plugin page?
- HTML in WooCommerce settings
- How to generate video out of images via WordPress plugin
- How can I get WordPress to save comments in markdown format?
- WooCommerce get_price returning wrong price when used via ajax
- How to ‘clone’ a wp plugin to make small changes
- Open Post Thumbnail in New Child Theme File in WordPress
- Where should I save an API key of my user when installing my plugin?
- Is Wrapping intval() Around esc_attr() Redundant for Escaping Input?
- Programatically download a plugin
- Redirecting to home page after login as custom role WordPress
- Add keywords meta to index.php page
- Custom form action to handle data inside a plugin
- Woocommerce plugin for minimum order and add-to-card-step
- Add Product Subtitle to Woocommerce Product Page
- Self deactivate plugins after an action occurs
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- woocommerce 3.2.1 not sending order notification emails
- WooCommerce Custom Product to checkout
- How to periodically scrape and cache strings from remote txt files. – My First Plugin
- Automatically add attributes to woocommerce product?
- WP Post Template – Templates in own folder
- Avoid class name collision when using third party libraries in plugins?
- wordpress plugin is not activating from widget
- Edit Yoast SEO breadcrumbs output [closed]
- How would I go about creating a user ranked post popularity page?
- Redirection of users away from wp-admin (but not administrators)
- Using a custom plugin to capture input data via Ajax and PHP
- How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
- How to enable specific plugin only based around shop manager role?
- code is working properly in Core PHP but writing coding in WordPress
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- woocommerce payment gateway callback not firing [closed]
- How to modify WCMP Rest API response?
- Fetch Children of Grouped Products Inside WooCommerce Product Loop
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Woocommerce dependent plugin
- How to check current user before all actions and filters?
- New databes tables with – WooCommerce – for developers [closed]
- Image upload and download from front-end
- WooCommerce: Building a page with user input which is used to query order status and external API and return a result
- Change commission_status paid when withdraw_status vendor is completed
- custom payment gateway in woocommerce failed to connect to remote api server
- wp_remote_get() returns 403 while file_get_contents() does not
- Replacing a plugin function with a custom renamed function doesn’t work
- How to output CMB2 select options from repeated groups select elements?
- 306 MB of wp_options occupied by WordPress SEO Plugin, is that normal? [closed]
- WooCommerce specifc variations for specific user role [closed]
- What are the specifics of WordPress development I need to know? [closed]
- Ajax call returning 0
- How to deal with WordPress and Pocket API to automate content curation on my hosted wordpress blog? [closed]
- WP All Import – Execute Imports
- How to replace WordPress Media Upload Window with user’s device window?
- Conditional attributes and logic per product category
- how to do login using woocommerce rest api From android
- Woocommerce Minimum Price for a Composite Product to add in cart
- How to create a custom post type that contains another custom post type?
- Perform internal redirect in WordPress?
- How to prevent plugins from loading jQuery