Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8930855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:59:12+00:00 2026-06-15T08:59:12+00:00

I’m trying to show latest Post Excerpt, Post Title and Featured Image on an

  • 0

I’m trying to show latest Post Excerpt, Post Title and Featured Image on an ASP page. To simplify the query I add the Permalink as a custom field for each Post. I have a query that gets all except Featured Image and I have another query that gets Featured image but I can’t work out how to merge them into one query.

// Gets Post Excerpt and Post Title

SELECT
 wp_posts.id, 
 wp_posts.post_title, 
 wp_postmeta.meta_value, 
 wp_postmeta.meta_key, 
 wp_posts.post_excerpt 
 FROM 
 wp_postmeta 
 INNER JOIN wp_posts p ON (wp_postmeta.post_id = wp_posts.ID) 
 WHERE post_id IN (
 SELECT wp_posts.id 
 FROM wp_posts 
 WHERE post_type = 'post' 
 AND post_status = 'publish' 
 AND meta_key = 'my_permalink' 
 ORDER BY post_date, wp_posts.id
 ) 
 ORDER BY wp_posts.post_date DESC, wp_postmeta.post_id 
 LIMIT 2

// Gets Featured Images for a Post

 SELECT p.*
      FROM wp_postmeta AS pm
     INNER JOIN wp_posts AS p ON pm.meta_value=p.ID 
     WHERE pm.post_id = $ID
       AND pm.meta_key = '_thumbnail_id' 
     ORDER BY p.post_date DESC 

Can anyone help me merge these queries? Thanks.

Sample data to be returned:
ID | post_title | post_excerpt | meta_value_my_permalink | featured_image_guid

** UPDATE *
I’ve managed to get the following which works fine except I can’t get more that one row as I get an error when I try and use ‘IN’ in a subquery
e.g. pm2.post_id IN (SELECT wp_posts.id FROM wp_posts WHERE post_type = ‘post’ AND post_status = ‘publish’ ORDER BY post_date DESC LIMIT 2)

SELECT 
  p.post_title,
  p.post_excerpt,
  pm.meta_value AS permalink,
  p2.guid as thumbnail,
  p2.post_title as image_alt
FROM
  wp_postmeta pm
  INNER JOIN wp_posts p ON (pm.post_id = p.ID),
  wp_postmeta pm2
  INNER JOIN wp_posts p2 ON (pm2.meta_value = p2.ID)
WHERE
  pm.post_id = (SELECT wp_posts.id FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1) AND 
  pm.meta_key = 'my_permalink' AND 
  pm2.post_id = (SELECT wp_posts.id FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1) AND 
  pm2.meta_key = '_thumbnail_id'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:59:13+00:00Added an answer on June 15, 2026 at 8:59 am

    A bunch of joins and a view as the subquery has given me what I need.

    SELECT 
      p.post_title,
      p.post_excerpt,
      pm.meta_value AS permalink,
      p2.guid AS thumbnail,
      p2.post_title AS thumbnail_alt
    FROM
      wp_postmeta pm
      INNER JOIN wp_posts p ON (pm.post_id = p.ID)
      INNER JOIN wp_postmeta pm2 ON (pm2.post_id = p.ID)
      INNER JOIN wp_posts p2 ON (pm2.meta_value = p2.ID)
    WHERE
      pm.meta_key = 'my_permalink' AND
      pm2.meta_key = '_thumbnail_id' AND 
      p.ID IN (SELECT * FROM vwLatestPostIds)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y’all
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.