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
- Function wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder
- register_taxonomy() take much queries
- Can anyone offer any help with this function?
- is there a benefit in using a constant over get_stylesheet_directory_uri?
- WooCommerce Tabs [closed]
- Shortcode with PHP issue “Undefined index”
- height should be set to auto to avoid pixelation in the post thumbnail function
- Can i put my shortcode inside a variable in php files?
- Moving code from theme header to functions.php
- Override a function defined in wp-includes/comment-template.php
- Show meta box only for default page template
- Can’t access site after making changes to the functions.php [closed]
- Custom array from a query only write the last row of the query
- Best way to use a large array in function
- Setting user nickname and displayname to shortened email
- How to check if a PHP string is different than meta field?
- Querying Database with wpdb
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- Displaying posts based on category
- Countdown to date function?
- calling a custom field value inside functions.php
- Custom meta box values are not getting saved for my custom post type
- Simple AJAX notification when the new post is added to the database
- Upload multiple files in randomly generated folder using wp_upload_bits
- Use $wpdb or other PHP script method to find/replace in WP database
- Noindex Posts From Certain Authors In WordPress
- Personalize checkout text
- WordPress check if current taxonomy has child
- get post id from wp_insert_post for get_template_part
- This function is deprecated; use mysql_real_escape_string() instead
- get_theme_mod outputs number when using WP_Customize_Cropped_Image_Control
- Adding an interior ‘hero’ area with some added php title customization
- Randomize Color Scheme Selection in Theme
- Include a file that has a function in it
- Execute Jquery when a specific page in my plugin is loading
- Call to a member function get_row() on a non-object, Unable to use global $wbdp inside a plugin
- AJAX function not working [closed]
- Modify WooCommerce used to get all orders in dashboard
- WordPress SQL Prepare
- Can’t log in to WordPress wp-admin after adding code to functions.php
- How to preload header logo image in WordPress? like what’s the code and where do I put it?
- Contain multiple page templates in one PHP custom template file in WordPress?
- How do I reopen the (Popup Maker) after entering the correct password for a password protected page?
- Display metabox galleries on specific page template in admin editor
- display condition based on post term and status
- Only the first image uploads
- Search by date in WordPress
- Hide a div if the fiels is empty
- Illegal string offset checkbox
- Custom plugin: how do I call a PHP file if settings option is set to true?
- removing the standard dashboard widgets in WP so I Can replace with custom
- Gravity Forms: How to add PHP function to confirmation conditional shortcode?
- wpdb->query returns different value to phpMyAdmin
- Trying to add some custom text into WordPress Post title via function.php
- What is the correct way to search 3 custom fields only in WordPress?
- How to change order inside foreach using wp_enqueue_script?
- Change header on one page in WordPress
- I got big white screen when i attach main style sheet of Html in functions.php
- Using Javascript On Page – Header and Footer Now Missing
- How do I get the value of a current user’s custom field?
- Adding extra data to shortcode attributes and pass it to JS with wp_localize_script
- Add Product Permalink in woocommerce admin order page
- Allow Comments by Default for Multiple Post Types
- Cleaner ‘for each’ loop for registering scripts in functions.php
- How do I make comment-reply-button with that takes to comment reply form on click
- How to get User Avatar Image with link to Author and User name in Html Title tag?
- How to generate customized filtered output for the gallery
- How to get all users by user_login as a json_encode array?
- Allow BBPress participant role to trash topics
- Display Year and Month from custom field + Age Calculator
- insert thumbnail image from php script
- WordPress rating by views [closed]
- Postmeta not saving
- Get author meta of all writers
- Trying to see if page is category or single and displaying title with appropriate heading tag
- Get null from POST
- Hide the content before the more tag in the “single page”
- Replace TinyMCE with Custom Built Editor
- Particular meta tag – viewport – insertion when dealing with plugin
- how to loop through blog posts in php
- WP Fatal error: Call to undefined function get_template_directory_uri()
- Remove default Image Sizes
- A better way to write this php function
- inner-wrap div pushing custom table far down on page
- Automatically change insurance quantity based on cart total [closed]
- /page/2/ redirect to 404
- How to pass value to add_filter wpcf7_form_tag from another function?
- hiddenQuestions.find is not a function
- require used as a function to load theme dependencies?
- How can I eliminate the top-level URL slug in WordPress while still being able to access child pages, particularly three levels deep or more?
- Check if User Meta has Existing Value
- Filtering with Attributes – how to display all non-queried products below query