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
- Deleting WordPress posts and media files based on author via MYSQL database
- 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
- WPDB Insert or if exists Update
- Checking if Database Table exists
- The MySQL alternatives: Do Percona Server and MariaDB work well with WordPress, and do they make WordPress go better?
- 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?
- “MySQL server has gone away” since update to 3.8
- Error establishing a database connection – with Debug Data
- Can I transfer a mysql database to another site?
- Database with mixed collation (utf8mb4 & utf8_general_ci)
- MySQL Syntax Error upon restoring database from backup [closed]
- Help running a MySQL query to update all wp_#_options tables in a Multisite install
- Using table lock with wp_insert_post?
- Is it safe to convert tables from MyISAM to InnoDB?
- Migrating database / content of non-CMS site to WordPress
- Delete all post meta except featured image Using SQL
- How do I properly update the WordPress database password?
- Adding new row to wp_post table
- How do I find which articles are missing a featured image in The WordPress database?
- WordPress Install and Database on separate hosting?
- Using GROUP CONCAT in my-sql query with wp_usermeta table
- Setup private content for specific users with daily updates [closed]
- How to fix database error duplicate entry
- How do I convert a MySQL database from utf8mb4 to utf8 encoding?
- WPDB SQL query with prepare() returning variable, not db value
- Query multiple tables at once?
- Problems with moving my WordPress site to another domain/server
- Custom WordPress Table wpdb
- Best practice to limit results in get_row()?
- How to migrate a database from a server to another
- Trouble running $wpdb->query() with last_insert_id
- how to encyrpt DB_PASSWORD in wp-config
- How can I detect right db type?
- Delete all posts that do NOT have a specific tag
- Changing order of db results when encoding to JSON
- How to display data from db in select list [closed]
- Second ezSQL initialization for MSSQL
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- Link multiple user databases together?
- Sql query to get all metadata for a post
- Performing CRUD operations on front end in wordpress
- Set a cron job to delete a specific database table table every midnight
- SQL database import #1046 error
- Bulk find & replace on WordPress posts/pages (minus image paths)
- How to import products in host instead of database on wordpress?
- I would like some help wth an SQL query to link posts with categories
- How do I loop/iterate through posts to edit all img tags?
- Where is the HTML-handler part in the wpdb class?
- next comment id number wordpress
- Correct and secure way to access a custom SQL database in a custom PHP template file
- Merging development site with live site
- How to retrieve user data based on role using SQL?
- Missing latest posts and options after DB migration via phpMyAdmin
- Check if a database is well installed
- live site do not update after importing sql database
- How do i get value from wp_postmeta?
- “MySQL server has gone away” since update to 3.8
- featured image not showing up with mysql_connect
- MySQL Database User: Which Privileges are needed?
- Import Excel (or csv) Table with user-data as subscribers to wordpress
- Getting deleted users in database
- Print output of Table Creation
- Understanding Redundant postmeta Tables in WordPress Database
- SQL errors when querying for something with apostrophes
- Naming conventions for database tables