Use the method get_var()
instead. I’ve also tidied up your code (if you’re gonna use double quotes, take advantage of them!) & added data escaping with the handy prepare()
method.
global $wpdb;
$cat_id = $wpdb->get_var(
$wpdb->prepare(
"SELECT category_id FROM {$wpdb->prefix}awpcp_categories WHERE category_name = %s",
$ad_cat
)
);
Related Posts:
- Update results, Before deleting the related category [closed]
- How to return number of found rows from SELECT query
- $wpdb->delete column values IN ARRAY()?
- wp query foreach deleting record returning only first or last item
- Custom array from a query only write the last row of the query
- wpdb prepare insert table doesn’t work
- I can’t update my data through $wpdb
- Add row to custom database Table and delete all rows older than 1 day
- Using wpdb to connect to a different database is not working
- MySQL database migration to WordPress
- How to edit the default database of WordPress [closed]
- Putting form result in my database
- How to properly prepare a column name if passed to a stored procedure?
- Can i use php sql functions instead of $wpdb?
- Check if post of title already exists
- How to use update and delete query in wordpress
- Custom query to get post names beginning with a digit
- How to make WordPress plugin check for database changes and then do something?
- How To Make Connection To WordPress Data Base In A Plugin?
- Changing user_nicename
- Does WordPress cache get_user_meta() results?
- WordPress will not operate correctly
- How to Join two tables from separate databases within WordPress
- simple wordpress ajax plugin not working when not logged in
- error importing localhost export file to server
- Would manually deleting the dumping data fix a “#1062 – Duplicate entry ‘1’ for key ‘PRIMARY'” phpMyAdmin error?
- How to sort results from a custom database table
- How can I call a row of user specific data from a custom table added to the WP Database
- How to merge local and live databases?
- How to track a users progress through pages by inserting data into WordPress Database?
- Import 10,000 Users into WordPress WITH a specific ID for each user
- WPDB: how to get the value of a field in a custom database table
- WP database error for comments_popup_link()
- if statement on database query
- Unusable menus and “Illegal widget setting ID: nav_menu_item[]” error
- Activation hook not creating table
- No wp-config.php file on local install of wordpress – site still displays
- WordPress Ajax Custom Query – High CPU LOAD
- “The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working
- How to migrate the posts from an old custom legacy blog to a new WordPress website?
- WordPress get pagination on wpdb get_results
- Different database query in function.php using mysqli
- How to create and work with custom data / tables (i.e., for arbitrary data)?
- Query String being Removed Creating a Pagination Issue within a Custom Plugin
- Ajax $wpdb not returning table data
- Converting MYSQL to WordPress $WPDB
- 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?
- database interactions using OOP
- WordPress Scheduled Event Request Blocking
- Accessing the database from a plugin outside of action hooks
- Can’t get wp_insert_post to work
- Trying to establish connection to External Database
- Create WP_Query to search for posts by their categories or their parent/child categories
- Getting id of poll from WP database
- How to insert a single row to WP database table?
- Basic wpdb update question
- wpdb Cannot Update column in Database
- Output: “Array”
- How to use mysql LIKE with wpdb?
- Delete database record using plugin from admin panel
- Set default Database Storage Engine when creating tables with plugins?
- Wpdb get->results to out the the month from the db
- WordPress WP_Query without query GET parameters
- How do I prepare strings for insertions as values into a MySQL table?
- How to use AJAX in WordPress in MYSQL query?
- WPDB – Read and write value from / to database
- How do I make this Metabox show current DB value?
- form $_post action value gets truncated after it passes through two forms
- How to Generate a list of Most Commented post?
- Why won’t this wpdb get_results query return results?
- WPDB secure custom form
- Why when I create a new post I found 2 record related to this post into the posts database table?
- Adding data to custom wordpress database table
- phpMyAdmin error #1062 – Duplicate entry ‘1’ for key ‘PRIMARY’
- populate select options from extra mysql table data
- Query the links Database
- How to display results from a data table with an encrypted user id?
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- SQL error with custom query
- MySQL Query Returns Array () In Shortcode
- Add posts to custom table in database instead of wp_posts
- What’s wrong in my PHP code? I’m using WordPress Astra Theme and I can’t insert data into my SQL
- 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
- Please help! I have a problem with getting wordpress databas
- Error establishing a database connection (Set-up locally)
- PHP Warning: mysqli_query(): after updating my websites php from 5.6 to 7.2
- MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?
- Conditional formatting on data fetched from MYSQL
- wp_update_post gives 500 internal error
- code that I can run, or a plug in to show what sql tables something pulls information from
- What is the correct way to search 3 custom fields only in WordPress?
- How to import woocommerce custom fields data into another site?
- Looping through custom data in a custom table to display all items in a post
- Need help with format of nested array in MySQL
- The plugin generated 225 characters of unexpected output during activation
- How to grab data from input and store it into custom table in database?