As the other gentlemen have mentioned in the comments, due to the libraries that source uses, strings are returned. If you need to convert to an integer for a comparison or function call, just use WordPress’s absint
function .
$int_id = absint( $wp_posts[0]->ID );
Also, not sure if your DB call is just simply an example, but I suggest using get_posts
, or better yet, a WP_Query
if possible. This allows you to maintain all of the sanitization those functions have built into them, keeping the security of your site pretty solid. Also remember to use wp_reset_query
after using the above to methods to ensure you are reverting back to the main loop.
Related Posts:
- Using wpdb to connect to a separate database
- MySQL Database User: Which Privileges are needed?
- Database synchronization between dev/staging and production
- WPDB Insert or if exists Update
- How can I make updates to a site, on a development copy, but then move updates back without overriding live site’s evolving database?
- get_results using wpdb
- $wpdb won’t insert NULL into table column
- Safest way to bulk delete post revisions
- Get error messages when $wpdb->insert() returns false?
- Detecting errors generated by $wpdb->get_results()
- Does dbDelta delete columns as well?
- wpdb update add current timestamp not working
- How to fetch Data in WordPress using MySQLi or $wpdb
- How can I make a WordPress database portable and url independent?
- How to delete all records from or empty a custom database table?
- wpdb->insert multiple record at once
- WordPress Unit Testing – Cannot Create Tables
- How to define composite keys with dbDelta()
- Does wpdb add considerable overhead on queries with large result sets?
- $wpdb->prepare() warning in WordPress 3.5
- Dealing with Many Meta Values, 30+
- When is it appropriate to create a new table in the WordPress database?
- Inserting data into custom tables
- Hook into $wpdb
- Display data from a non wordpress database on a page template
- How does $wpdb handle COUNT(*)
- Is it possible to switch the data layer within WordPress?
- store simple data in get_option()
- How might I retrieve a featured post image from an external WP site and display it as a link back?
- WordPress database error: [Query was empty] [closed]
- Export wordpress table to excel
- How to close wpdb connection? [duplicate]
- How to delete outdated, wrongly sized images in _wp_attachment_metadata?
- Inserting Post Meta From SQL
- Have multiple local wordpress installs share a wp-content folder and database
- Why does dbDelta() not catch MysqlErrors?
- Connecting to external oracle database
- Can I use $wpdb for my custom tables in the WordPress database?
- How to implement content from external database into WordPress text page? [closed]
- Cloning and syncing a WordPress website
- Can’t save ajax value to database
- What causes the “max_user_connections” warning on WordPress frontend?
- $wpdb variable throw this error Call to a member function get_results() on a non-object in
- Updating all rows of table with $wpdb
- What actions affect files, DB, or both?
- Safe way to find last inserted id in a table?
- How do I have a user upload a blog post and then retrieve that to display in a card on the site?
- $wpdb->insert not inserting all rows
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- wpdb Insert unknown post data dynamic foreach loop
- How do I get database rows from a custom table using wpdb?
- SELECT rows between two datetimes when the range is dynamic [closed]
- How to insert a value to decimal type field using wpdb->prepare?
- Insert NULL value using prepare()
- What is my error trying to create a new table in the database?
- Help with $wpdb on custom code
- “BS_” rows in postmeta table
- $wpdb->insert duplicating rows
- How to rerieve comments and their replies from DB
- Can I use a wpdb object to connect to a non-WordPress Oracle database [duplicate]
- How to have differents sites share the same tables of DB?
- Where is the HTML-handler part in the wpdb class?
- A WP dev site that displays content from a live site’s database but cannot write to wp_posts?
- Help posting values to DB on submit using $wpdb->query
- WordPress Database Query works in phpMyAdmin but not in the code
- How to add download link from database on custom page template?
- 2 $wpdb queries causing error Table ‘wp_postmeta’ is specified twice, both as a target for ‘UPDATE’
- WPCLI search and replace in a particlar site dir effect another site-dir
- insert data from a form:: Warning Empty query mysqli::query()
- How can I get $wpdb to show MySQL warnings?
- Correct and secure way to access a custom SQL database in a custom PHP template file
- About wp database hooks (error establishing connection)
- How to get specific table by current user login
- Merging development site with live site
- Using $wpdb to insert data into a table
- How To connect to the same WordPress database with different database user
- Accessing content from third party as native posts in WordPress
- Should I Use only wpdb Class to Write Custom Queries?
- Call to a member function insert()
- I have include wp-config, should I add global $wpdb also?
- Processing a lot of $wpdb isn’t insert all the data
- One WP Database outside localhost and two connections
- Can’t Install WordPress (local) Failed to open file wp-includes/wp-db.php
- using same mysql user with many databases
- Get id from database
- How can I retrieve data from alternate database using wpdb class?
- Pulling values from a sepcific row in table
- Creating Tables in WordPress Database
- Share WordPress Database
- MySQL Database User: Which Privileges are needed?
- Inserting into data into external DB using WPDB
- Insert Extra fields added in the front end registration form to DB
- How to use remote db tables in current config? [duplicate]
- $wpdb->insert not working for last select option
- $wpdb->prepare returns empty array
- How to delete field using WPDB?
- Uploading to WordPress Database
- $wpdb->update is not working until next page refresh. Is there one more step?
- how to run tests using different db connection
- SQL errors when querying for something with apostrophes