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
- Check if post of title already exists
- How to use update and delete query in wordpress
- How to make WordPress plugin check for database changes and then do something?
- Does WordPress cache get_user_meta() results?
- How to Join two tables from separate databases within WordPress
- 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
- WPDB: how to get the value of a field in a custom database table
- WP database error for comments_popup_link()
- 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 get pagination on wpdb get_results
- Different database query in function.php using mysqli
- 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()
- database interactions using OOP
- WordPress Scheduled Event Request Blocking
- Accessing the database from a plugin outside of action hooks
- Create WP_Query to search for posts by their categories or their parent/child categories
- WSoD being caused by this piece of code
- WordPress not reflecting changed of the database
- How WordPress reacts to a lack of memory of the server [closed]
- Execute long and heavy processes
- database sent to a JSON file
- 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
- Using custom tables for old posts
- Help with a $wpdb MySQL Query
- Issue running db create table query from static method
- How to retrieve the data from the sever and displaying it in a page?
- $wpdb returns duplicate posts
- Mixing variables into an array when inserting values
- Should I use WordPress to skin a database website?
- Creating Database Table vs. Adding MetaData to Post & User
- WordPress and MySQL: trying to print data using PHP from user_meta custom field data
- Most commented posts by time period (last 12h, last 24h and etc)
- How can I add a new row in a separate database when someone registers via WordPress?
- 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 to use AJAX in WordPress in MYSQL query?
- form $_post action value gets truncated after it passes through two forms
- WPDB secure custom form
- phpMyAdmin error #1062 – Duplicate entry ‘1’ for key ‘PRIMARY’
- 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()
- MySQL Query Returns Array () In Shortcode
- 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
- How to import woocommerce custom fields data into another site?
- Need help with format of nested array in MySQL
- The plugin generated 225 characters of unexpected output during activation
- Advanced WordPress SQL Query
- can’t delete a row from post_meta table
- Unable to pass variable to database
- Send data from plugin to external database
- MySQL query in WordPress with AJAX
- How to set max users to 17.000
- Passed variable gets undefined variable error on insert on next page
- MySQL queries in WordPress
- How to fetch results from database
- How to connect database table to each registered wordpress user.
- Using the same shortcode to show any table from the database
- Querying multiple meta_keys in WordPress SQL query
- Let users register weight each day and save it in DB
- MySQL update text field with ‘
- Fetching wpdb data from a php file seems to break?
- Create custom table for wordpress custom registration flow
- Custom form that stores data in mysql database
- How to get data (not value or name) from radio options to POST to database
- Error resetting database index using ALTER TABLE in $wpdb->query
- How can I update a value of a field depending on outside source?
- Issue with WordPress Plugin Activation Hook and Table Creation
- Function wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder