$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
- #1067 – Invalid default value for ‘post_date’ when trying to create a new column
- Deleting WordPress posts and media files based on author via MYSQL database
- Deleting empty meta key values
- Sql query to get all metadata for a post
- Recovery – Restore Database after moving folder location locally
- Replacing javascript link in WordPress database without getting mysql syntax errors
- Performing CRUD operations on front end in wordpress
- I imported an restore an database and It shows #1067 – Invalid default value for ‘user_registered’
- Set a cron job to delete a specific database table table every midnight
- How to edit custom table data in frontend
- Job and Employee Performance Tracking with Product Safety
- local wordpress broke after changing URL
- how to access 2nd Mysqli Database from different server for wordpress
- Migrating meta_key and meta_value from old theme to new one
- Error establishing a database connection – WordPress setup, everything else is working
- How can I find user role in Mysql?
- 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?
- Exporting Post ID, Post Title, Primary Category and Primary Category ID
- Featured image from custom to WordPress database
- Help posting values to DB on submit using $wpdb->query
- What’s the easiest way to connect external database and display data on wordpress?
- WordPress Database Query works in phpMyAdmin but not in the code
- How to map data on CSV to web pages?
- Is there a way for two deferent themes to consume two different DB on a same WP instance?
- wpdb query to insert images in to post/page gallery
- How to set posts to draft in bulk based on the content of the post
- next comment id number wordpress
- Database structure for thousands of posts
- 2 $wpdb queries causing error Table ‘wp_postmeta’ is specified twice, both as a target for ‘UPDATE’
- 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 can I get $wpdb to show MySQL warnings?
- Correct and secure way to access a custom SQL database in a custom PHP template file
- How to get specific table by current user login
- Merging development site with live site
- mySQL database size large, but tables size less
- How to retrieve user data based on role using SQL?
- spambot registering without providing email or password, bypassing registration process
- After renaming MySQL database, I can no longer access my Blog page
- $wpdb not working
- How To connect to the same WordPress database with different database user
- Possible to restore wordpress database from mysql56 and sqlite files?
- WordPress Database Posts Table query
- How much post meta data is too much?
- Hang Up Followed By Can’t select database
- WordPress character set issue
- How to extract some part of WordPress full source code
- can’t delete a row from post_meta table
- Mysql Queries per Visit – Crazy High
- Missing latest posts and options after DB migration via phpMyAdmin
- Check if a database is well installed
- Create a new table on the database and save parameters from a contact form
- live site do not update after importing sql database
- Link wordpress with a SQl + MongoDB + .NET
- Why is converting my database to UTF-8 truncating entries?
- Widgets with *internal* links do not display after database migration
- using same mysql user with many databases
- How to add data from wordpress tables to new database tables you have created
- “MySQL server has gone away” since update to 3.8
- Why are my WordPress post queries so slow?
- 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