php - MySQL Query on Wordpress database -


"postprint" itemprop = "text">

I'de post like a WordPress database that likes to take a mysql query on the title and recovery of the first image link of the last 6.

WordPress Core Functions are not allowed because I want to show them on an external site. In other words, I need a pure mysql query

I can not show titles like this:.

  $ result = mysql_query ("where wp_posts select from * Post_status = 'publish' and post_type = 'id_listing' order ID range range 6", $ db); While ($ record = mysql_fetch_assoc ($ result)) {echo '& lt; Li & gt; $ Record ['POST_TITLE'] .. "& Lt; / li & gt;"; }   

But how to recover the first image (if present) related to these posts?

In the wp_posts table for your image record, what post_perrent is on the published page? Not mine, and if you do not have it, you will need to search through the Post_saint field for each published page, from which you can search for the image tag (or the tags used for your images).

I have read from other articles, it seems that sometimes post_parent will look back on the parent page for an image. If this is true for your database, then you should be able to do something like this:

  select post.id as post_id, post.post_title, POST_URL, image_detail. As the post.guid image_id, image_detail.post_title as IMAGE_TITLE, as the word wp_posts from the left as image_url in the form of id_detail.guid JOIN (select post_parent, first_image_id as min (id) as wp_posts From where post_type = 'attachment' and post_parent 'image /%' group post_mime_type of your choice) image_latest on post.id = image_latest.post_parent on left image_detail.id = imag E_latest.first_image_id Join wp_posts image_detail where post.post_status = 'publish';    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -