admin管理员组文章数量:1287661
How do I extract the last published post?
I would be grateful if someone can just point out the relevant action hooks that I should check out. I have seen publish_post, edit_post, save_post, get_the_tags, sanitize_** functions in post.php
but so far no success.
I want to export the entire array of the last published post from the database. How do I do that?
How do I extract the last published post?
I would be grateful if someone can just point out the relevant action hooks that I should check out. I have seen publish_post, edit_post, save_post, get_the_tags, sanitize_** functions in post.php
but so far no success.
I want to export the entire array of the last published post from the database. How do I do that?
Share Improve this question edited Oct 30, 2021 at 19:28 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Mar 20, 2012 at 4:56 BAUBAU 751 silver badge7 bronze badges 03 Answers
Reset to default 1This is how I do it. You may want to reset and call it as a function in case you want to reuse.
// Most Recent
function nt_mostrecent( $count ) {
$my_query = new WP_Query( array(showposts => $count, order => 'DSC', orderby => 'date'));
while ($my_query->have_posts()) : $my_query->the_post();
$posts .= '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
endwhile;
return $posts;
wp_reset_query();
}
Thank You! I sorted this out myself thanks...
For any one who stumbles upon this, here's the resolution...
// Get the last n number of posts.
$args = array( 'numberposts' => 'n' ); // replace n with the number of posts
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.$recent["post_title"].'" >' . $recent["post_title"].'</a> </li> ';
echo '<li>Tags '.print_r($recent).'</li> ';
}
Using wp-cli:
wp post list --order='DESC' --orderby='ID' --field='ID' | head -1
本文标签: exportExtract the last published post
版权声明:本文标题:export - Extract the last published post 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741243089a2364360.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论