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
- Can i use php sql functions instead of $wpdb?
- How to use update and delete query in wordpress
- 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
- Would manually deleting the dumping data fix a “#1062 – Duplicate entry ‘1’ for key ‘PRIMARY'” phpMyAdmin error?
- Import 10,000 Users into WordPress WITH a specific ID for each user
- WP database error for comments_popup_link()
- if statement on database query
- Unusable menus and “Illegal widget setting ID: nav_menu_item[]” error
- No wp-config.php file on local install of wordpress – site still displays
- WordPress Ajax Custom Query – High CPU LOAD
- How to migrate the posts from an old custom legacy blog to a new WordPress website?
- 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?
- WordPress Scheduled Event Request Blocking
- 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?
- WSoD being caused by this piece of code
- PHP Fatal error: Uncaught mysqli_sql_exception: Table doesn’t exist in wordpress/wp-includes/wp-db.php
- $wpdb->update with multiple parameters gives error
- Store a default value for a transient on plugin activation
- How WordPress reacts to a lack of memory of the server [closed]
- database sent to a JSON file
- inserting a post from an extern php file but post content doesn’t show on wp site
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- $wpdb->insert() does not Insert record in a table
- Not connecting to database in file with multiple MySQL connections
- Issue running db create table query from static method
- WordPress Block developer from exporting Database via PHP
- How to retrieve the data from the sever and displaying it in a page?
- Mixing variables into an array when inserting values
- Building a REST API for your web app exposes primary keys of DB records?
- Use $wpdb or other PHP script method to find/replace in WP database
- Basic wpdb update question
- wpdb Cannot Update column in Database
- Output: “Array”
- Delete database record using plugin from admin panel
- Wpdb get->results to out the the month from the db
- How do I prepare strings for insertions as values into a MySQL table?
- 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?
- 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
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- SQL error with custom query
- 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
- Please help! I have a problem with getting wordpress databas
- 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
- Looping through custom data in a custom table to display all items in a post
- The plugin generated 225 characters of unexpected output during activation
- How to grab data from input and store it into custom table in database?
- Insert data from form to database
- Rewrite SQL query as a prepared statement and use in foreach loop
- Unable to pass variable to database
- Send data from plugin to external database
- Accessing external database: ERR_INCOMPLETE_CHUNKED_ENCODING
- How to set max users to 17.000
- Passed variable gets undefined variable error on insert on next page
- two wordpress sites, two themes, one database, same content
- Insert double entry in DB
- Querying multiple meta_keys in WordPress SQL query
- Custom query_posts() parameter
- MySQL update text field with ‘
- How to pass username into form that sends data to database
- Insert into db with foreach problem
- Display total count of products in orders of a specific order status
- Execute multiple PHP Snippets causes error?
- How can I update a value of a field depending on outside source?
- Can’t insert into a database wordpress