The main problem, I see in your code, is that you use query
method of wpdb
and assume that it is PDO statement object…
But it is not.
Take a look at wpdb Codex:
https://codex.wordpress.org/Class_Reference/wpdb
query
method is used to run custom queries on DB – that’s all.
What you want to use is get_results
.
And BTW, seriously, do never concatenate user input with SQL statements. Such data should ALWAYS be escaped properly – otherwise you create SQL Injection vulnerability. You can use prepare
method to create safe queries in WP.
I also don’t think you should echo wp_send_json_success
– I’m pretty sure this function already echoes values…
And one more thing… Your hooks are wrong. You send action wc_get_...
, but then use hooks like wp_ajax_call_wc_get...
(so your php code assumes the action is call_wc_get...
.
Related Posts:
- How to use AJAX in WordPress in MYSQL query?
- MySQL query in WordPress with AJAX
- How to return number of found rows from SELECT query
- Can i use php sql functions instead of $wpdb?
- $wpdb->delete column values IN ARRAY()?
- Custom query to get post names beginning with a digit
- simple wordpress ajax plugin not working when not logged in
- Jquery ajax to custom php file: returning blank data
- Can’t use get_results() in ajax query
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Use ajax to update_post_meta
- AJAX in WordPress, sending coords data to MySQL and show after into map
- WordPress get pagination on wpdb get_results
- Converting MYSQL to WordPress $WPDB
- How to Fetch values from WP database based on selected option value by onchange using PHP?
- Why is variable not working on custom sql query using wpdb?
- Show MySQL errors that occur when I excute $wpdb->insert()
- Any possible way to make $wpdb->get_results() return anything else than array?
- Checking for new message using AJAX and PHP. Server overload?
- Can’t get wp_insert_post to work
- WSoD being caused by this piece of code
- I want to select the from values from database in WordPress? [closed]
- Update results, Before deleting the related category [closed]
- wp query foreach deleting record returning only first or last item
- Refresh table data with Ajax
- Database query works fine outside WordPress
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- $wpdb->insert() does not Insert record in a table
- Help with a $wpdb MySQL Query
- Custom array from a query only write the last row of the query
- $wpdb returns duplicate posts
- Mixing variables into an array when inserting values
- Use $wpdb or other PHP script method to find/replace in WP database
- How can I add a new row in a separate database when someone registers via WordPress?
- Basic wpdb update question
- I can’t update my data through $wpdb
- A $_POST should occur when submit form but is not?
- Output: “Array”
- How to use mysql LIKE with wpdb?
- Cannot access $wpdb, comes back NULL
- Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
- How do I prepare strings for insertions as values into a MySQL table?
- Live search from database table
- Processing ajax call to php to insert into mysql database
- form $_post action value gets truncated after it passes through two forms
- Why won’t this wpdb get_results query return results?
- WPDB secure custom form
- Add row to custom database Table and delete all rows older than 1 day
- select a single val though a table in wordpress
- populate select options from extra mysql table data
- Query the links Database
- MySQL Query Returns Array () In Shortcode
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- Passing in MySQL prepare statement parameter separately throwing error
- Convert a column of a table containing an Array as response in HTML
- Database SQL query error
- MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?
- Conditional formatting on data fetched from MYSQL
- What is the correct way to search 3 custom fields only in WordPress?
- Using wpdb to connect to a different database is not working
- autocomplete in wordpress using ajax with json-data
- Rewrite SQL query as a prepared statement and use in foreach loop
- Prepared DB Query from _POST array
- Advanced WordPress SQL Query
- Ajax not updating to database
- Passed variable gets undefined variable error on insert on next page
- Run insert if no entry otherwise run update with ajax
- MySQL queries in WordPress
- Using the same shortcode to show any table from the database
- AJAX with Selectbox Plugins (Select2, Chosen, Selectize)
- MySQL database migration to WordPress
- How to display inputted data in Ajax without button or click event
- WordPress Query -> Ajax Query
- how to display tables via ajax
- Error resetting database index using ALTER TABLE in $wpdb->query
- Putting form result in my database
- How can I update a value of a field depending on outside source?
- Fatal error: Call to undefined function mysql_connect()
- the_date() not working
- PHP calling AJAX function that relies on passed PHP function values not working
- WordPress Ajax Data problem
- PHP/MySQL issues when running WP on EC2 cloud [closed]
- ajax_object is not defined when ajax calls the function
- How to prevent those PHP variables from being cached on WordPress?
- Use ajax from function.php
- database interactions using OOP
- Ajax loaded form replaces form action with Ajax url
- prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
- get_posts() and WP_query limits ‘AND’ conditions to a maximum of 6 for meta value queries in WordPress
- [jQuery]Adding shortcode
- Display parent and child taxonomies in separate drop down select fields
- WordPress admin-ajax.php 400 bad request
- javascript variable to wordpress php variable
- Output votes to div dynamically in wordpress
- Load more posts using AJAX based on posts inside WP_Query
- Store GA Client ID in User DB
- Not getting ajax success response on insert/update row to database
- Need help with format of nested array in MySQL
- Site doesnt work once PHP changed to 7.1
- can’t delete a row from post_meta table