$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
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- difference between primary key and unique key
- phpMyAdmin – Error > Incorrect format parameter?
- MySQL Database User: Which Privileges are needed?
- Why is my database import losing text widget data?
- Will it break my site if I delete all transient records in wp_options table?
- Why WordPress choose data serialization over json_encode?
- Please explain how WordPress works with MySQL character set and collation at a low level
- Reset Post IDs to less than 64bit integer
- WordPress database scalability from the code perspective
- Does WordPress use the InnoDB engine for MySQL by default?
- Where are image paths to product category images stored in WordPress database
- How to delete outdated, wrongly sized images in _wp_attachment_metadata?
- Split WP install between 2 databases?
- Why does dbDelta() not catch MysqlErrors?
- Is altering a default WordPress database table update safe?
- What causes the “max_user_connections” warning on WordPress frontend?
- what to do when your WordPress database is too large?
- Change all http to https in mysql databse?
- WordPress and automated MySQL backups to a different host
- Scheduling posts in database
- WordPress site uses MyISAM, should I switch to InnoDB necessary?
- Uppercase to sentence case for post titles
- WordPress mysql table double prefixes
- Storing data for a wordpress plugin
- WordPress database import: Row size too large
- Advanced SELECT query with condtional statements
- Why do mass updates to post_content shows in front end, but not in edit screen?
- Error establishing database connection – high traffic?
- Bulk-create posts from SQL database
- Improve performance by removing unnecessary database queries
- Redirecting to old domain after migration website
- WordPress Database Huge wp_usermeta Table
- Migrating to WordPress Recipe Plugin and Some SQL Issues
- How to prevent/delay MySQL connections when an object cache is used?
- Uknown meta entries in wp_postmeta
- Insert Query not working in the form
- Error establishing a database connection,
- Changing between Local Host DB to Production DB and in reverse
- pull data from a remote wordpress database
- Options on how to Display member specific data from a MS SQL database
- Query Column of Specific ID from Database Table
- WP MultiSite: Can’t select database error after changing to new domain
- Link image with data from the wpdb
- How to connect and insert data in database of wordpress?
- Buddypress avatar image in database [closed]
- Installing local to live WP into subdirectory
- WordPress SQL – How to Check for Category?
- Cloning blog to localhost via WAMP
- Counting post and changing roles in mysql database. Query not code
- How to save EXIF metadata in WordPress database?
- MSQL database wp_postmeta has meta key tve_revision
- Deleting empty meta key values
- I imported an restore an database and It shows #1067 – Invalid default value for ‘user_registered’
- Exporting Post ID, Post Title, Primary Category and Primary Category ID
- What’s the easiest way to connect external database and display data on wordpress?
- 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’
- mySQL database size large, but tables size less
- After renaming MySQL database, I can no longer access my Blog page
- How To connect to the same WordPress database with different database user
- How much post meta data is too much?
- WordPress character set issue
- Create a new table on the database and save parameters from a contact form
- Link wordpress with a SQl + MongoDB + .NET
- Why is converting my database to UTF-8 truncating entries?
- How to add data from wordpress tables to new database tables you have created
- How to back-up a database on IIS
- If meta_key exists then don’t select this post?
- Uploading to WordPress Database
- Have WordPress Use a Different Database for users