$Featured_image = $wpdb->get_results("
SELECT p.*
FROM net_5_postmeta AS pm
INNER JOIN net_5_posts AS p ON pm.meta_value=p.ID
WHERE pm.post_id = $da_id
AND pm.meta_key = '_thumbnail_id'
ORDER BY p.post_date DESC
LIMIT 15
",'ARRAY_A');
A related solution, to query for posts WITHOUT providing a post ID (ordered by post date, and using the wp_ database prefix):
SELECT
p1.*,
wm2.meta_value
FROM
wp_posts p1
LEFT JOIN
wp_postmeta wm1
ON (
wm1.post_id = p1.id
AND wm1.meta_value IS NOT NULL
AND wm1.meta_key = "_thumbnail_id"
)
LEFT JOIN
wp_postmeta wm2
ON (
wm1.meta_value = wm2.post_id
AND wm2.meta_key = "_wp_attached_file"
AND wm2.meta_value IS NOT NULL
)
WHERE
p1.post_status="publish"
AND p1.post_type="post"
ORDER BY
p1.post_date DESC
Related Posts:
- WordPress and MySQL: how to transfer Meta_key and Meta_Value from one post_id to another
- Inserting Post Meta From SQL
- Migrating non-WordPress CMS to WordPress, lots of data to move — possible solutions?
- How to solve slow WordPress site caused by attachment_metadata
- Delete all post meta except featured image
- 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
- Delete all post meta except featured image Using SQL
- wpdb_prepare with multiple or condition
- SQL Error wp_commentmeta – incorrect table definition
- How do I get the posts within a certain year/date(with sql query)?
- Create table from array with prepare
- Why this query is not showing any result on wordpresss home page?
- 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
- “BS_” rows in postmeta table
- 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
- How do i get value from wp_postmeta?
- Migrated to Namecheap, now Trouble with Database & wp-config [closed]
- export individual posts to text files or a single csv file
- 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’
- 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)
- Error Code: 2013. Lost connection to MySQL server during query
- 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 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?
- importing data from non-wordpress mysql db
- “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
- 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
- Routine to convert custom post meta from old to new value
- Setup private content for specific users with daily updates [closed]
- 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
- Does post_meta data need to be unserialzed?
- 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
- How and where is wordpress adding mySQL content to database?
- Using AND and bracket grouping in SQL not working
- Is my way to change WordPress server is correct?
- How to delete a particular row in a database table
- Files on Localhost, Database on Server
- Remote database -> massive response time increase?
- Custom Post Type not showing anything added by code anymore?
- Getting “Error Establishing a Database Connection” on localhost in new Mac OSX Lion environment
- custom tables in wordpress Database? (can i just create them with sql?)
- Accidently changed the GUID
- Replacing javascript link in WordPress database without getting mysql syntax errors
- How to edit custom table data in frontend
- local wordpress broke after changing URL
- how to access 2nd Mysqli Database from different server for wordpress
- Error establishing a database connection – WordPress setup, everything else is working
- Help posting values to DB on submit using $wpdb->query
- How to map data on CSV to web pages?
- wpdb query to insert images in to post/page gallery
- Database structure for thousands of posts
- Search and Replace in Windows XAMPP site
- The function is deprecated; use mysql_real_escape_string() instead
- WPCLI search and replace in a particlar site dir effect another site-dir
- How can i syn wordpress user table with a stand-alone php script?
- insert data from a form:: Warning Empty query mysqli::query()
- How to get specific table by current user login
- $wpdb not working
- WordPress Database Posts Table query
- Hang Up Followed By Can’t select database
- Mysql Queries per Visit – Crazy High
- using same mysql user with many databases
- Why are my WordPress post queries so slow?
- Weird WP -Cli Error Connection Refused
- How to find fresh (last modified) and sql backup?
- Understanding Redundant postmeta Tables in WordPress Database
- Database table prefix different between wp-config.php and in database
- Naming conventions for database tables