Integrate admin plugin into template. Very interesant (live search + autocomplete with wp rest api, in vanilla js)

I need a live search with wp rest api with autocomplete, in vanilla js. I found this plugin makes exacly what I needed. (I dont need this code as a plugin, its not a problem, but if it helps to make it easier, if anyone knows how to do this code works without it beign a plugin, let me know.)

TUTORIAL: https://sabrinazeidan.com/wp-rest-api-search-with-autocomplete-with-vanilla-js/

Github: https://github.com/sabrina-zeidan/sz-rest-api-tut

In this case, the plugin creates a page into the tools section but it doesnt gives me support to integrate it into the template , and I dont know how execute it into the template by myself. The code is shown above:

<?php /**  * Plugin Name: SZ WP REST API Tutorial  * Description: It's an example of WP REST API usage for search with autocomplete with vanilla JS  * Plugin URI:    * Author:      Sabrina Zeidan  * Author URI:  https://sabrinazeidan.com  * License:     GNU General Public License v2 or later  * License URI: http://www.gnu.org/licenses/gpl-2.0.html  *  */  defined( 'ABSPATH' ) or die();  class SZ_WP_REST_API_Tut {      function __construct() {                 add_action( 'admin_menu', array( $  this, 'admin_menu' ) ); //Add an item to the Tools menu                add_filter('plugin_action_links_' . plugin_basename(__FILE__), array( $  this, 'plugin_actions_links' ) ); //Add a link on Plugins page                  add_action( 'rest_api_init', array( $  this, 'rest_api_init') ); // Initialize the REST API routes.            }        public function admin_menu() {            $  hook = add_management_page( 'SZ WP REST API', 'SZ WP REST API', 'manage_options', 'sz-search', array( $  this, 'admin_page_content' )); //Add a page to the Tools menu            add_action( "load-$  hook", array( $  this, 'admin_page_load' ) );//hook to load stuff on that page     }     function plugin_actions_links( array $  actions ) {             return array_merge( array(             'sz-search'    => sprintf('<a href="%s">%s</a>', esc_url( admin_url( 'tools.php?page=sz-search' ) ),esc_html__( 'See it', '' ))), $  actions );     }     function admin_page_load() {         add_action( 'admin_enqueue_scripts', array( $  this, 'enqueue_scripts' ) ); // Load needed JavaScript and CSS          }          function enqueue_scripts() {             wp_enqueue_style( 'awesomplete-css', plugin_dir_url( __FILE__ ) . 'awesomplete/awesomplete.css'); //Awesomplete widget             wp_enqueue_script('awesomplete-js', plugin_dir_url( __FILE__ ) . 'awesomplete/awesomplete.js'); //Awesomplete widget             wp_enqueue_script('sz-search', plugin_dir_url( __FILE__ ) . 'search.js', array('awesomplete-js')); //Our Awesomplete settings are here             wp_localize_script('sz-search', 'szsearch', array(                 'search_url' => home_url( '/wp-json/sz-search/search?term=' ), // URL to access REST API endpoint                 'nonce' => wp_create_nonce('wp_rest') ) //For authorization             );       }          function rest_api_init() {          register_rest_route( 'sz-search', '/search', array(              'methods'  => 'GET',             'callback' => array( $  this, 'sz_rest_api_search'), //exactly how we search             'permission_callback' => function( WP_REST_Request $  request ) { return current_user_can( 'manage_options' ); } //Restrict endpoint to  internal calls          ) );     }          function sz_rest_api_search( WP_REST_Request $  request ) {         $  search_term = $  request->get_param( 'term' );//Our input from the field         if ( empty( $  search_term ) ) {             return;         }                //The way we're gonna search             $  args = array(                 'post_type' => 'post',                 'post_status' => 'publish',                 'posts_per_page'   => 3,                 'fields'   => 'ids',                 's'             => $  search_term,                 'no_found_rows' => true,                   'update_post_meta_cache' => false,                 'update_post_term_cache' => false,                 );             $  the_query = new WP_Query( $  args );                                          $  this_blog_found_posts = $  the_query->posts;                 $  temp = array();                 foreach( $  this_blog_found_posts as $  key => $  post_id) {                      $  temp = array(                         'ID' => $  post_id,                         'permalink' => get_permalink($  post_id),                         'label' => get_the_title($  post_id),                         );                     $  posts[] = $  temp;                                                            }                         if (!empty($  posts)) return $  posts;     }             function admin_page_content() {         echo '<div class="wrap">';         echo '<h1>' . esc_html_x( 'SZ WP REST API Search with autocomplete with Vanilla JavaScript', 'admin page title', 'sz-wp-rest-api-search' ) . '</h1>';                echo '<p>This is a search field intended to demostrate a result of WP REST API. Does it work? :)</br>';         echo '<p><input type="text" size="80" id="sz-search-field" name="sz-search-field" value="" placeholder="Start typing the title of the post...">';//Our search field         echo '<br><input type="hidden" size="80" id="sz_result_id" name="sz_result_id" value="">';//Hidden field to pass post ID         echo '<br><input type="hidden" size="80" id="sz_result_permalink" name="sz_result_permalink" value="">';//Hidden field to pass post permalink         echo '</div>';     } } new SZ_WP_REST_API_Tut(); //Let's do it! ?> 

What Ive tried is to create the object, and then call the function that shows the input field.

<?php     $  search = new SZ_WP_REST_API_Tut();     $  search->admin_page_content(); ?> 

This shows the input field, but it doesnt make the live search works. I would try more solutions by myself but in this case I dont know what more can I do, I’m stucked.

Unmanaged Dedicated + Full Root Access,Intel Xeon 56xx (4 Cores),24/7 Live Support- H

Hostpoco.com offers optimal performance dedicated servers and the best price.
Dedicated servers provide a secure hosting environment if you are storing sensitive data or are handling a large amount of website traffic. At Webrimium, we offer fast and affordable dedicated servers that will be ready in 24 hours.

*Dedi Elite Plan:110 /Monthly

– Intel Xeon 56xx (4 Cores)
– HDD Storage
– 16 GB RAM
– 2x HDD SATAII 3TB 7.20 Storage
– 4 Free IP Address
– 1Gbps uplink 10 TB traffic included
– cPanel/whm License $45 /month
– Additional IP address $3 /month/IP
– 99 % Uptime Guarantee
– 24/7 Live Support
– SSH Access
– 7 Days Money Back Guarantee

For more Plans, visit: https://www.hostpoco.com/low-cost-dedicated-server.php

Features that make special than others :

*RDNS Availability
Client’s can request us to set their desired RDNS records for server IP’s

*Free 5 IP’s
Our dedicated server comes with free 5 IP’s and there is no additional cost for it

*No Contracts
There are no special contracts and purely offer monthly based billing cycle with dedicated server plan’s

*Unmanaged Server
All our servers are unmanaged and its the client who is supposed to manage their server by own

*Multiple DC
We have multiple DC locations available for unmanaged servers and US location is default one

Still, have questions? Please contact us!:sales@hostpoco.com

Follow us on Twitter: https://twitter.com/HostPoco
Find us on Facebook: https://www.facebook.com/HostPoco/

Do any pattern exists for renaming live a MongoDB collection?

Do any pattern exists for renaming a MongoDB collection live in production environment? The collection is accessed both for reading and for writing in a non sharded environment. The requirement is to not have downtime. Some different microservices access the collection in different ways. The result must be obtained in a progressive way, releasing updated services independently from each other.

For relational databases several patterns were discovered and documented in the excellent book Refactoring Databases: Evolutionary Database Design by Scott Ambler and Pramod Sadalage and I would have used the Rename Table pattern to implement if the database was relational, that but it seems that with MongoDB this is not possible.

Additional css urls changed from S3 links to live site links when downloaded the site for local development

So, I have a website with the Hueman theme. It’s all working properly on the live domain name but I needed to make some changes so I downloaded the whole website (files and database) on my local computer to make the changes and publish them on the live site.

What happened is extremely intriguing, at least to me. The header has a large background image done through css from Appearance > Customize > Advanced Options > Additional CSS and that image on the live site is an Amazon S3 link (all my media files go there) but when I set up the site locally the link in the "Additional CSS" changed to point to WordPress’ uploads directory on the live site and obviously that’s a 404 error.

The plugin which handles my S3 upload is "WP Offload Media Lite" and I have the "Amazon Web Services" plugin as well.

Here is my live site additional css:

/* You can add your own CSS here.  Click the help icon above to learn more.  Use this field to test small chunks of CSS code. For important CSS customizations, it is recommended to modify the style.css file of a child theme. http//codex.wordpress.org/Child_Themes */  /*@import url('https://fonts.googleapis.com/css?family=Kalam&display=swap'); */ html {     max-width: 100%;     overflow-x: hidden; }  #header {     background: url(https://imagecurve.s3.eu-central-1.amazonaws.com/wp-content/uploads/2020/12/21134758/Book-on-a-pebble-beach-propped-open-with-a-stone-hero-1920x650-1.jpg) center 0px no-repeat; }  nav#nav-header {     background: #33363b !important;     opacity: 0.9; }  #nav-header.nav-container {     box-shadow: none;     -webkit-box-shadow: none; }  #nav-header li a {     font-weight: bold; }  #header .pad {     max-width: 480px;     margin: 80px auto;     background: rgb(68, 68, 68);     opacity: 0.8;     padding: 30px 30px 20px;     padding-top: 28px;     padding-bottom: 30px;     text-align: center; }  #header .site-title, #header .site-description {     float: none; }  #header .site-description {     font-size: 17px;     color: rgb(255, 255, 255);     font-weight: 500;     text-align: center;     line-height: 40px;     padding: 0;     font-style: normal;     margin-left: 0; }  /* Subscribe form */ .widgetGuts .success {     background: #01c01e; }  .widgetGuts .subscribeButton {     background: #3b8dbd;     color: #fff;     padding: 8px 14px;     font-weight: 600;     display: inline-block;     border: none;     cursor: pointer;     -webkit-border-radius: 3px;     border-radius: 26px; }  #frm-subscriptionFrontsimplesubscribe-2 dl dt:first-child {     margin-bottom: 5px; }  #simplesubscribe-2 > h3 {     font-size: 20px; }  .post-meta .post-date {     display: none; }  /* Contact forms */ .wpcf7-form span.wpcf7-not-valid-tip {     position: static;     display: inline-block;     width: 100%;     margin-top: 8px; }  .wpcf7-form input[type=text], .wpcf7-form input[type=email] {     width: 100%; }  .wpcf7-submit {     border-radius: 26px !important; }  .nf-form-cont .submit-wrap input {     background: #3b8dbd;     color: #fff;     padding: 8px 14px;     font-weight: 600;     display: inline-block;     border: none;     cursor: pointer;     -webkit-border-radius: 3px;     border-radius: 3px; }  article.post-26078 > .post-inner, article.post-28116 > .entry {     max-width: 800px; }  #frm-subscriptionFrontsimplesubscribe-2 #frm-email {     width: 100%;     padding: 6px 8px;     box-sizing: border-box;     border-radius: 3px;     border: 1px solid #c7c7c7; }  #header-widgets {     float: none; }  #header-widgets p {     margin-bottom: 0; }  .ap-form-field .wp-switch-editor {     height: 25px; }  .social-links li:nth-child(3), .social-links li:nth-child(5) {     display: none; }  #header .site-description {     font-size: 22px !important; }  #explore-legends {       background: #dff3d5;     border: 2px solid #82b965;     padding: 65px 0 25px 0;     text-align: center;     margin-bottom: 20px;     border-radius: 18px; }  #explore-legends h3 {     color: #8a8989;     margin-bottom: 0;     font-family: 'Kalam', cursive; }  #explore-legends a {         background: #82b965;     display: inline-block;     padding: 7px 12px;     text-align: center;     color: white;     clear: right;     margin: 12px 0 35px 0;     border-radius: 13px;     width: 100%;     max-width: 165px;     box-sizing: border-box;     font-weight: bold; }  #explore-legends i {     font-style: italic;     color: #5d5d5d; }  @media(max-width: 1200px) {     #header-widgets {         margin-top: 5px;         display: block !important;     } }  @media(max-width: 1280px) {     #header {         background: url(https://imagecurve.s3.eu-central-1.amazonaws.com/wp-content/uploads/2020/12/21134754/Book-on-a-pebble-beach-propped-open-with-a-stone-hero-1280x500-1.jpg) center 0px no-repeat;     } }  @media(max-width: 1024px) {     #header {         background: url(https://imagecurve.s3.eu-central-1.amazonaws.com/wp-content/uploads/2021/01/06051411/Book-on-a-pebble-beach-propped-open-with-a-stone-hero-1024x420-2.jpg) center 0px no-repeat;     } }  @media (max-width: 785px) and (min-width: 720px) {     #nav-header li:nth-last-child(2) {         display: none;     } }  @media(min-width: 720px) {     #nav-header li:last-child {         float: right;     }      #nav-header li:nth-last-child(2) {         float: right;     } }  @media (max-width: 720px) {     #header .container .group.pad {         max-width: 252px;     }      #header .site-title {         padding: 0;     } }  @media (max-width: 580px) {     .wp-pagenavi span.extend {         display: block;     } }  @media (max-width: 480px) {     #header .container .group.pad {         margin: 50px auto;     }      #header {         background: url(https://imagecurve.s3.eu-central-1.amazonaws.com/wp-content/uploads/2021/01/06051527/Book-on-a-pebble-beach-propped-open-with-a-stone-hero-480x520-2.jpg) center center no-repeat;     } } 

Here is my local additional css:

/* You can add your own CSS here.  Click the help icon above to learn more.  Use this field to test small chunks of CSS code. For important CSS customizations, it is recommended to modify the style.css file of a child theme. http//codex.wordpress.org/Child_Themes */  /*@import url('https://fonts.googleapis.com/css?family=Kalam&display=swap'); */ html {     max-width: 100%;     overflow-x: hidden; }  #header {     background: url(https://www.imagecurve.com/wp-content/uploads/2020/12/21134758/Book-on-a-pebble-beach-propped-open-with-a-stone-hero-1920x650-1.jpg) center 0px no-repeat; }  nav#nav-header {     background: #33363b !important;     opacity: 0.9; }  #nav-header.nav-container {     box-shadow: none;     -webkit-box-shadow: none; }  #nav-header li a {     font-weight: bold; }  #header .pad {     max-width: 480px;     margin: 80px auto;     background: rgb(68, 68, 68);     opacity: 0.8;     padding: 30px 30px 20px;     padding-top: 28px;     padding-bottom: 30px;     text-align: center; }  #header .site-title, #header .site-description {     float: none; }  #header .site-description {     font-size: 17px;     color: rgb(255, 255, 255);     font-weight: 500;     text-align: center;     line-height: 40px;     padding: 0;     font-style: normal;     margin-left: 0; }  /* Subscribe form */ .widgetGuts .success {     background: #01c01e; }  .widgetGuts .subscribeButton {     background: #3b8dbd;     color: #fff;     padding: 8px 14px;     font-weight: 600;     display: inline-block;     border: none;     cursor: pointer;     -webkit-border-radius: 3px;     border-radius: 26px; }  #frm-subscriptionFrontsimplesubscribe-2 dl dt:first-child {     margin-bottom: 5px; }  #simplesubscribe-2 > h3 {     font-size: 20px; }  .post-meta .post-date {     display: none; }  /* Contact forms */ .wpcf7-form span.wpcf7-not-valid-tip {     position: static;     display: inline-block;     width: 100%;     margin-top: 8px; }  .wpcf7-form input[type=text], .wpcf7-form input[type=email] {     width: 100%; }  .wpcf7-submit {     border-radius: 26px !important; }  .nf-form-cont .submit-wrap input {     background: #3b8dbd;     color: #fff;     padding: 8px 14px;     font-weight: 600;     display: inline-block;     border: none;     cursor: pointer;     -webkit-border-radius: 3px;     border-radius: 3px; }  article.post-26078 > .post-inner, article.post-28116 > .entry {     max-width: 800px; }  #frm-subscriptionFrontsimplesubscribe-2 #frm-email {     width: 100%;     padding: 6px 8px;     box-sizing: border-box;     border-radius: 3px;     border: 1px solid #c7c7c7; }  #header-widgets {     float: none; }  #header-widgets p {     margin-bottom: 0; }  .ap-form-field .wp-switch-editor {     height: 25px; }  .social-links li:nth-child(3), .social-links li:nth-child(5) {     display: none; }  #header .site-description {     font-size: 22px !important; }  #explore-legends {       background: #dff3d5;     border: 2px solid #82b965;     padding: 65px 0 25px 0;     text-align: center;     margin-bottom: 20px;     border-radius: 18px; }  #explore-legends h3 {     color: #8a8989;     margin-bottom: 0;     font-family: 'Kalam', cursive; }  #explore-legends a {         background: #82b965;     display: inline-block;     padding: 7px 12px;     text-align: center;     color: white;     clear: right;     margin: 12px 0 35px 0;     border-radius: 13px;     width: 100%;     max-width: 165px;     box-sizing: border-box;     font-weight: bold; }  #explore-legends i {     font-style: italic;     color: #5d5d5d; }  @media(max-width: 1200px) {     #header-widgets {         margin-top: 5px;         display: block !important;     } }  @media(max-width: 1280px) {     #header {         background: url(https://www.imagecurve.com/wp-content/uploads/2020/12/Book-on-a-pebble-beach-propped-open-with-a-stone-hero-1280x500-1.jpg) center 0px no-repeat;     } }  @media(max-width: 1024px) {     #header {         background: url(https://www.imagecurve.com/wp-content/uploads/2021/01/Book-on-a-pebble-beach-propped-open-with-a-stone-hero-1024x420-2.jpg) center 0px no-repeat;     } }  @media (max-width: 785px) and (min-width: 720px) {     #nav-header li:nth-last-child(2) {         display: none;     } }  @media(min-width: 720px) {     #nav-header li:last-child {         float: right;     }      #nav-header li:nth-last-child(2) {         float: right;     } }  @media (max-width: 720px) {     #header .container .group.pad {         max-width: 252px;     }      #header .site-title {         padding: 0;     } }  @media (max-width: 580px) {     .wp-pagenavi span.extend {         display: block;     } }  @media (max-width: 480px) {     #header .container .group.pad {         margin: 50px auto;     }      #header {         background: url(https://www.imagecurve.com/wp-content/uploads/2021/01/Book-on-a-pebble-beach-propped-open-with-a-stone-hero-480x520-2.jpg) center center no-repeat;     } } 

The live site is here.

I tried googling but nothing sensible was found. I am confused, how could this happen?

Live life in every move,Smile that you carry with your shoes

A few different plaid patterns and various hues highlight this new colorway of the new balance outlet online. Taking a look at this New Balance 997 the runner gets covered in three different plaid prints which land on the toe, ankle, and tongue in a canvas-type construction. Joining the plaid prints are pops of burgundy, black, and green suede on the overlays along with tan leather on the midfoot. Yellow “N” branding on the side panels, a white rubber midsole, and a black rubber outsole finish things off on this New Balance 997.
</br></br>
converse deutschland is celebrating the 45th anniversary of the final season of the American Basketball Associate with the Converse Pro Leather “Birth of Flight.”August 1976 saw the merge of the ABA with the NBA and signaled a moment in time that would change the artistry of basketball forever. Ultimately, the combination of these two contrasting leagues – one focused on the game’s sport and rigor while the latter encouraged artistry and flair – would break down barriers for future generations of hoops. To capture the essence of Dr. J as he broke basketball’s “flight” barrier through his infamous free-throw line dunk, Converse’s Pro Leather Birth of Flight style is inspired by the league that first sparked creativity and individualism amongst athletes.
</br></br>
There’s a new Neue Ankünfte model (no pun intended) releasing this summer as we bring you a first look at the New Balance 920. The new silhouette from the runner brand is inspired from both the 900 series as well as the 1000 series. Part of their Made In The UK series, the New Balance 920 takes on a mesh, suede, and nubuck construction all over the upper with embroidered “920” branding on the heels, ENCAP midsoles, and reflective “N” logos on the side panels.
</br></br>
Bestseller sneakers have always been a vehicle for others to tell a story, reflect their personal identity. With the ability for a product to deliver meaning more important now than ever before, Tremaine Emory aka Denim Tears, presents a powerful provocation to young Black men and women through his latest collaboration: If the Chuck is a classic and iconic expression of American culture, how does its meaning transform when it reflects the black experience and identity?

Clicking custom plugin admin menu redirects to “No Update Required” on live site

I built a custom WordPress plugin that sends woocommerce purchase info to a CRM. The plugin works perfectly on localhost. But on live site, whenever I click on the admin menu, I always get redirected to "No Update Required" page.

enter image description here

Here is my main plugin file:

/**  * Plugin Name: Woo Crm  * Description: Sends customer data to the CRM on purchase.  */  if (!defined('ABSPATH')) {     echo 'I am a plugin I cannot do anything when called directly.';     exit; }  // Config define('PLUGIN_NAME', 'Woo Crm'); define('PLUGIN_SLUG', 'woo_crm'); define('PLUGIN_URL', plugin_dir_url(__FILE__)); define('PLUGIN_PATH', plugin_dir_path(__FILE__));  // Imports require_once(PLUGIN_PATH . 'utils/utils.php'); require_once(PLUGIN_PATH . 'views/views.php'); require_once(PLUGIN_PATH . 'services/crm/crm.php'); require_once(PLUGIN_PATH . 'views/components/settings/settings.php');  class WooCrm {     function __construct()     {         // Register Styles         add_action('admin_enqueue_scripts', array($  this, 'register_styles'));          // Create Menu Page         add_action('admin_menu', array($  this, 'plugin_setup_menu'));          // Add Settings Fields to Menu Page         add_action('admin_init', array('settings', 'init'));          // Woocommerce hook         /**          * First check if WooCommerce is activated          * Then check if hook isn't empty          */         if (class_exists('WooCommerce')) {             $  hook = get_when_to_send_data_hook();             if (!empty($  hook)) {                 add_action($  hook, array($  this, 'woo_order_create_client'));             }         }     }      function woo_order_create_client($  order_id)     {         // Create client logic     }      function plugin_setup_menu()     {         $  icon_url = PLUGIN_URL . "public/images/dash-icon.png";         add_menu_page(__(PLUGIN_NAME, PLUGIN_SLUG), __(PLUGIN_NAME, PLUGIN_SLUG), 'manage_options', PLUGIN_SLUG, array('views', 'admin'), $  icon_url);     }      function register_styles()     {         wp_register_style('woo_crm_admin', PLUGIN_URL . 'public/css/admin.css');         wp_enqueue_style('woo_crm_admin');     }  }  new WooCrm(); 

Any help would be highly appreciated.

[Hostpoco.com]★Christmas Offer★60% OFF & Lifetime 40% OFF★24×7 live support.

Hurry up!!!

This Christmas Hostpoco is going to offer a 60% flat discount and a 40% lifelong discount with web hosting plans. So if you are really planning to buy web hosting for your website, then there is no preferable time than now for your needs. We are sure that such offers come for few days in a year and you will have to wait almost for a year if you miss these offers.

Offer Start From:
================================================
Start Date: 18/12/2020 – End Date: 31/12/2020
================================================

You can take advantage of these deals using the below promo codes (for yearly+ billing cycles):
Coupon Code: XMAS60 60% Flat Discount for all shared, reseller, and WordPress hosting plans
Coupon Code: XMAS40 40% Lifetime off for all shared, reseller, and WordPress hosting plans

Promo Codes
Kindly copy and use the required offers coupon code at the time of checkout:

*WordPress Web Hosting: 60% One Time DiscountXMAS60
*Linux SSD Shared Web Hosting: 60% One Time DiscountXMAS60
*Linux HDD Shared Web Hosting: 60% One Time DiscountXMAS60
*High Resource Windows Hosting: 60% One Time DiscountXMAS60
*Linux HDD/SSD Shared/Reseller Web Hosting : 40% Lifetime Recurring DiscountXMAS40
*Windows Plesk Shared Web Hosting: 40% Recurring DiscountXMAS40
*100% Free Linux Shared Web Hosting: Direct Signup URL

All our web hosting plans come with the below key features :
– Instant Activation
– Multiple DC locations
– 30 days money-back guarantee
– Free Auto SSL
– Lets Encrypt SSL
– On-Demand SSH Access
– Free migration service
– Easy upgrades available
– Mail channels to route emails
– Max emails per hour
– 1GB memory supported
– Complete DDoS protection
– On-demand manual scan
– Antivirus available
– Single click script installer
– Perfect for WordPress, e-commerce, and heavy sites
– CPanel as control panel
– Free SEO Tools
– Max Email Accounts
– Unlimited Space for email accounts
– Unlimited FTP accounts
– Unconditional refund within 30 days
– 24×7 live chat support
– 24×7 support ticket service

USA, France, Netherlands web Hosting, Instant Activation, Fast Server, Fast support

BUY NOW:
https://hostpoco.com/web-hosting-offer-2021.php

For more Hosting plan details, please visit:https://hostpoco.com/

In case you have any questions, you can contact our sales department by initiating a chat or by dropping an email to Sales@hostpoco.com.

Change AJAX Live Post Search Loop into foreach

I was told that the reason for why the live post search does not work is because the loop needs changing into a foreach.

This is the code:

add_action( 'wp_ajax_data_fetch' , 'data_fetch' ); add_action( 'wp_ajax_nopriv_data_fetch', 'data_fetch' ); function data_fetch() {      global $  wpdb;     $  post_search_query = $  wpdb->get_results("SELECT * FROM wp_posts where post_type = 'post' and post_title like '%'".esc_attr( $  _POST['search_keyword'] )."'%'");          if( $  post_search_query->have_posts() ) :                  while( $  post_search_query->have_posts() ): $  post_search_query->the_post(); ?>                          <h5><a href="<?php echo esc_url( post_permalink() ); ?>"><?php the_title();?></a></h5>             <span class="live-search-product-excerpt"><?php the_excerpt(); ?></span>              <?php endwhile;         wp_reset_postdata();     endif;     die(); } 

The search is dead. It shows nothing. Can someone please help me with this as I am at a loss. Here is the rest of the code:

add_shortcode('live_search', 'live_search_shortcode'); function live_search_shortcode(){      $  live_search = '<input type="text" class="live-search" name="postSearch" id="postSearch" placeholder="Type to Live Search"></input>     <div id="datafetch"></div>';          return $  live_search; }  add_action('wp_footer', 'jquery_live_search_data_fetch'); function jquery_live_search_data_fetch() { ?>      <script type="text/javascript">                  (function($  ){              var searchRequest = null;                                  jQuery(function (){                                      var minlength = 3;                                  jQuery("#postSearch").keyup(function (){                                          var that = this,                                      value = jQuery(this).val();                                  if (value.length >= minlength){                                      if (searchRequest != null)                      searchRequest.abort();                                  searchRequest = jQuery.ajax({                                      type: "POST",                     url: "<?php echo admin_url('admin-ajax.php'); ?>",                 data: {                 action: 'data_fetch',                 search_keyword : value                 },                                  dataType: "html",                 success: function(data){                                          if (value==jQuery(that).val()) {                                              jQuery('#datafetch').html(data);                     }                 }             }         );     } else {      jQuery('#datafetch').html( '' );     }   } ); }); } (jQuery));     </script> <?php }