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
- 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
- Detecting errors generated by $wpdb->get_results()
- wpdb update add current timestamp not working
- 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
- Dealing with Many Meta Values, 30+
- 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?
- WordPress database error: [Query was empty] [closed]
- Export wordpress table to excel
- How to close wpdb connection? [duplicate]
- Have multiple local wordpress installs share a wp-content folder and database
- Connecting to external oracle database
- How to implement content from external database into WordPress text page? [closed]
- Cloning and syncing a WordPress website
- Updating all rows of table with $wpdb
- What actions affect files, DB, or both?
- Add search Value to wp_list_table pagination
- How to execute mulitple statement SQL queries using $wpdb->query?
- Is $wpdb->prepare escaping to much? How to use it properly?
- When and why should I use $wpdb different return types?
- How wordpress accesses its own database
- Remove database entries where post_date > expiration date
- Error connecting to DB in /wp-includes/wp-db.php on line 1538 [closed]
- How to fix unchanged URLs in Database after running serialized search and replace script?
- Merging WordPress posts from different databases
- How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?
- How to use a different database to list and manage comments in the backend
- Who is responsible for data sanitization in WordPress development?
- Cannot update custom database table row
- Search and replace special characters (å,ä,ö) for image attachments only in database
- wpdb_prepare with multiple or condition
- Show last modified date of database
- $wpdb->insert is not working
- Extracting the post_id via the wp_insert_post action (external db query)
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- Multiple wp_options tables to share content across installs
- Select two sums with single get_var statement
- $wpdb->replace: WHERE?
- Create table from array with prepare
- Update from 4.5 to 4.6 failing
- Localhost to Staging to Development Dynamic WP-CONFIG
- Setup 3 Sites To Connect To 1 Database and Share Data
- WordPress running SQL query to update database from form
- $wpdb->insert Giving duplicates
- WPDB SQL query with prepare() returning variable, not db value
- Have working sql query… trying to adjust it to use $wpdb
- creating new field on mysql
- Why user_pass column in wp_users table is varchar(64)
- $wpdb->query can’t insert data
- Custom WordPress Table wpdb
- How to fetch records from database WordPress
- Best practice to limit results in get_row()?
- AJAX wp-mysql running too slow
- CreateOrUpdate in WordPress
- Problem migrating to localhost
- Trouble running $wpdb->query() with last_insert_id
- How to get a list of WordPress default database tables?
- Using $wpdb | checking entered email against existing emails in db
- Can local WordPress installs share /wp-content/ folder and database?
- Optimizing function that automatically creates internal links based on post title string
- Get results from wordpress data custom table
- Outputting query results
- Creating and Using Tables in the WordPress Database
- How do I have a user upload a blog post and then retrieve that to display in a card on the site?
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- SELECT rows between two datetimes when the range is dynamic [closed]
- How to insert a value to decimal type field using wpdb->prepare?
- What is my error trying to create a new table in the database?
- 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
- How to add download link from database on custom page template?
- 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
- Accessing content from third party as native posts in WordPress
- Should I Use only wpdb Class to Write Custom Queries?
- 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
- Share WordPress Database
- MySQL Database User: Which Privileges are needed?
- Insert Extra fields added in the front end registration form to DB
- $wpdb->insert not working for last select option
- How to delete field using WPDB?