I want to fetch latest 3 post from wordpress with title,description ,featured image, date of publish using mysql query or using xmlrpc api

I want to display it to jsf site. Currently I am using xmlrpc with jwordpress. I have also access to wordpress db.

Solutions

write a query in mysql by descending your post uploaded date with limit 3

SELECT * FROM tablename ORDER BY added_date DESC limit 3

You can get the title, description and date of publish of latest 3 posts by

SELECT post_title, post_content, post_date
FROM wp_posts 
WHERE post_type='post' 
AND post_status='publish' 
ORDER BY post_date 
DESC LIMIT 3;

And featured images for the above three posts by

SELECT guid 
FROM wp_posts AS a 
INNER JOIN ( 
    SELECT meta_value 
    FROM wpsys_postmeta AS b 
    INNER JOIN ( 
        SELECT ID FROM 
        wpsys_posts 
        WHERE post_type = 'post' 
        AND post_status = 'publish' 
        ORDER BY post_date 
        DESC LIMIT 3 ) AS tbl1 
    ON b.post_id = tbl1.ID and b.meta_key='_thumbnail_id' ) as tbl2 
ON a.ID = tbl2.meta_value;

Note: 1) Check your table prefix. Here table prefix is wp_

2) Make sure featured image exists in your latest 3 posts otherwise the second query will result in failure.

<?php 
    $args = array( 'numberposts' => '3' );
    $recent_posts = wp_get_recent_posts( $args );
?>

As taken from Wordpress Codex

Similar questions

Want to change color of post<h1> title if it has no featured image set for that post
So on my wordpress blog and most other wordpress blogs, you can set a featured image. If you don't set a featured image I have it default to a background image that says "new update" however the default background image i have set is much less eye grabbing than the custom ones made for the post. To solve the issue of posts with custom featured imag...
Change Post Publish Date to Post Modified Date in All Places
I need to change post publish date to modify date every where in my theme. I know that I can use the_modified_date() function to display post modify date. But changing in every place takes too much time. Is there any way to change it using action hook or filter? (All theme in just one place)
Wordpress publish_post hook not getting featured image and meta on first publish, but works on updating title
I've been struggling to find a solution for this and I don't know if it's the Gutenberg editor or if it's the hook publish_post. Hook: I'm using the post meta, featured image and title to post to a third party API. The API verifies the data and then returns a unit hash which I store in the post meta open_unit. I'm also logging the data and response...
Fetch the latest post with attachment image
What I want to do seems to be simple but I can't get around it. I'd like to get the latest post that has an image attachment. A little help would be appreciated. Thanks Lita

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy .