First of all your query is wrong. The right query is
$mypost = $wpdb->query($wpdb->prepare("SELECT post_content FROM $wpdb->posts WHERE ID = %d", 2));
Second the $wpdb->query
will returns an integer value indicating the number of rows affected/selected. You can check here
http://codex.wordpress.org/Class_Reference/wpdb#General_Syntax
If you want generic result you can use $wpdb->get_results
http://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results
$mypost = $wpdb->get_results($wpdb->prepare("SELECT post_content FROM $wpdb->posts WHERE ID = %d", 2));
For getting single value result you can also use $wpdb->get_var
http://codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Variable
$mypost = $wpdb->get_var($wpdb->prepare("SELECT post_content FROM $wpdb->posts WHERE ID = %d", 2));
Related Posts:
- Inserting Post Meta From SQL
- How to execute mulitple statement SQL queries using $wpdb->query?
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- Query WordPress database by registered date and role
- Size article thumbnails and retrieve them directly from database
- wpdb_prepare with multiple or condition
- SQL Error wp_commentmeta – incorrect table definition
- WordPress and MySQL: how to transfer Meta_key and Meta_Value from one post_id to another
- How do I get the posts within a certain year/date(with sql query)?
- Create table from array with prepare
- Why does changing Database Table Prefixes result in loss of content?
- SQL query to set posts in bulk based on the post content
- $wpdb->get_var – What value is returned when zero records are found?
- DB prefix not updating
- I wanted to Know that how can I give ingore to 0000-00-00 in my config file
- How to create index (sql) to a meta_key?
- Delete all users meta that named: user_avatar
- The MySQL Connection could not be established., before it was joomla but i have change it into worpress
- Migrated to Namecheap, now Trouble with Database & wp-config [closed]
- export individual posts to text files or a single csv file
- SQL query : Select a thumbnail for a media
- why you don’t Implement PDO for access every thing to database
- SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- Rename a table in MySQL
- How should I tackle –secure-file-priv in MySQL?
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- How do I restore a dump file from mysqldump?
- Error Code: 2013. Lost connection to MySQL server during query
- 1052: Column ‘id’ in field list is ambiguous
- 1052: Column ‘id’ in field list is ambiguous
- difference between primary key and unique key
- phpMyAdmin – Error > Incorrect format parameter?
- How to do a batch insert in MySQL
- Why is my database import losing text widget data?
- Checking if Database Table exists
- How to fetch Data in WordPress using MySQLi or $wpdb
- Connect to database using wordpress wp-config file
- How To Export/Import WordPress (MySQL) Database Properly Via Command-Line?
- How to define composite keys with dbDelta()
- Is it possible to define two databases for one installation?
- Display data from a non wordpress database on a page template
- Bulk Update of Custom Post Type Post Status through SQL
- How do I add indexes to WordPress Database?
- Huge wp_options table
- “MySQL server has gone away” since update to 3.8
- Block search SQL from happening
- Can I transfer a mysql database to another site?
- MySQL Syntax Error upon restoring database from backup [closed]
- Help running a MySQL query to update all wp_#_options tables in a Multisite install
- Scheduling posts in database
- Is it safe to convert tables from MyISAM to InnoDB?
- Emojis getting converted to “?”
- How do I properly update the WordPress database password?
- WordPress Install and Database on separate hosting?
- Error establishing database connection – high traffic?
- Using GROUP CONCAT in my-sql query with wp_usermeta table
- Migrating to WordPress Recipe Plugin and Some SQL Issues
- Migrating from PDO using SQLite to clean new install using MySQL
- Which data is written and stored in the database when read-only (non-posting, non-commenting) users visit the site?
- Duplicated site isn’t recognized as a site
- Error establishing a database connection,
- Changing root password in PHPMyAdmin for WordPress Database when going live
- How to properly check if a table exists in WordPress Database using Show Tables Query
- Can’t update WordFence Options, clear data manually
- Is it possible to have more than 1 MySQL database in my WordPress blog?
- How and where is wordpress adding mySQL content to database?
- Using AND and bracket grouping in SQL not working
- Options on how to Display member specific data from a MS SQL database
- Delete/Replace words from X to Y in post content
- Query Column of Specific ID from Database Table
- How to delete a particular row in a database table
- How to create more than one new wpdb object?
- Buddypress avatar image in database [closed]
- Remote database -> massive response time increase?
- WordPress SQL – How to Check for Category?
- Getting value from database table depending on field value
- Getting “Error Establishing a Database Connection” on localhost in new Mac OSX Lion environment
- Cloning blog to localhost via WAMP
- custom tables in wordpress Database? (can i just create them with sql?)
- Accidently changed the GUID
- MSQL database wp_postmeta has meta key tve_revision
- How to edit custom table data in frontend
- local wordpress broke after changing URL
- “BS_” rows in postmeta table
- Exporting Post ID, Post Title, Primary Category and Primary Category ID
- Help posting values to DB on submit using $wpdb->query
- How to set posts to draft in bulk based on the content of the post
- 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
- mySQL database size large, but tables size less
- $wpdb not working
- Hang Up Followed By Can’t select database
- WordPress character set issue
- Link wordpress with a SQl + MongoDB + .NET
- Why is converting my database to UTF-8 truncating entries?
- SQL query to rewrite all media URLs to end with .webp
- Weird WP -Cli Error Connection Refused
- How to find fresh (last modified) and sql backup?