You need to repalce the PDO connection object with WPDB object. And for the kind of query in your example, looks like the best way to do it is with $wpdb->getcol. Something like this (didn’t test):
if ( isset( $_GET['term'] ) ){
global $wpdb;
$term = filter_var( $_GET['term'], FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE );
if ( is_null( $term ) ) {
echo json_encode( array() );
}
else {
$return_array = $wpdb->get_col(
$wpdb->prepare(
"SELECT supplier_company
FROM {$wpdb->prefix}_teleapo_supplier
WHERE term = %s",
$term
)
);
$return_arr = $return_arr ? $return_arr : array();
/* Toss back results as json encoded array. */
echo json_encode( $return_arr );
}
}
Related Posts:
- Display fields as values in array from external SQL DB
- Trying to establish connection to External Database
- How to insert a single row to WP database table?
- WSoD being caused by this piece of code
- How to use mysql LIKE with wpdb?
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- Modify post image in full size
- posts_clauses drop ACF get_field function
- Cleaning up WordPress to improve performance?
- List of all theme customizer control types?
- Modify previous and next text from pagination links
- How can I modify the permalink via a filter?
- wp_set_object_terms and arrays
- Shortcode putting html such as
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- Output a WooCommerce product custom field in WooCommerce using get_post_meta()
- How to check If Oembed is empty or not
- Can’t load WP function into external function
- Call External Object in Class Function During Callback
- Image as Sales Badge
- How to Arrange PHP Files to Allow for Multiple Types of Pages?
- Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?
- Show css depending on activity type in BuddyPress activity-loop [closed]
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- Update results, Before deleting the related category [closed]
- Return a numerical function value in Customizer controls
- Css loads very slow [closed]
- Show when user is online/offline in real time on user_profile.php
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Scrape external webpage for first image and add it to new post
- theme_root returning a truncated URI
- Call to undefined function get_userdata() in plugin
- Log in / Log Out Custom Button
- how to test for all children (including multilevel grand-childern) of page
- Dilemma of Populating all the categories in a drop down list
- Add item to top of menu using a filter in functions.php
- Notify users only on post publish
- Limit Taxonomy Output in Conditional Statement
- wp_redirect only works on main site and not on other sites
- Mixing variables into an array when inserting values
- How to modify the default feed via a function
- require_once() if a product in woocommerce contains a tag [closed]
- Loop over Array and get the distinct ids
- How do I change this function from two returns to one string to show sku and dimensions in WooCommerce cart?
- Shortcode for Listing Users from Meta Value?
- I can’t update my data through $wpdb
- Wpdb get->results to out the the month from the db
- Display css ONLY on most recent post of specific category?
- How to remove the space before the ellipsis in excerpt?
- How can I use custom menus with a Bootstrap WordPress theme?
- how to enqueque code in a php file from functions.php
- Only load certain artists on this page
- Add row to custom database Table and delete all rows older than 1 day
- Get the alt text of the image in a array
- Convert all uploaded PNG files to PNG-8 format
- Make table disappear when fields are left blank?
- Uses for function: wp_update_user
- How to Redirect Buddypress Directories To Login Page For Non Logged in Users
- Woocommerce order status payment
- How to define a rule in functions.php that ONLY disables the default wp functionality that undesirably changes ‘&’ to ‘#038;’?
- Unzip file in functions.php, and add it to cron
- Add Block Before Entry Title Using PHP
- Display logged in user name and lastname on page
- How to Add a cutsom slug to my custom author role
- Dynamically populate parameter in Gravity Forms using PHP
- How to output the taxonomies that are assigned to each custom post?
- Conditional formatting on data fetched from MYSQL
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Exclude category from function – PHP
- How to escape echo for input tag?
- Including user data in “new user notification email”
- Display current user metadata on WordPress page
- Reload page with a different shortcode when a user selects from a dropdown
- Refresh page after login with litespeed cache
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- Woocommerce Add custom “Add to cart button” in single page with tags
- Populate Posts based on category selected using AJAX that means without page refresh
- remove_action() not working in page template – Genesis
- Why transition_post_type hook is called twice for the same post?
- Can’t get_users info by using json_encode
- What is wrong in this code?
- Page returning ID from array, how to return the correct values for post in acf wordpress
- Modify php code to pass a page id as a parameter in order to create a breadcrumb
- Show custom default avatar instead of gravatar
- Permission error on plugin save
- Removing all my hardcoded URLs with get_site_url()
- WordPress 2014 Theme – Featured Content with multiple tags?
- Display default WordPress login/registration form into a modal window
- Highlight main menu when on specific posts or pages
- Pull GET parameter from URL in functions.php
- Adding Gravity Form With if(is_page) Is Not Working
- ajax form function error
- Display custom meta box in my template file
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- How to display the date under the post title?
- Simple Probléme in wordpress
- Need help with conditional logic for menus
- Custom Admin Menu Report for Specific User ID
- WordPress / PHP: Check if column has value and then check if value in array
- how to create twitter card without plugin in wordpress website?