I’ve just started learning PHP/Wordpress yesterday – here is one of my first plugins. Unfortunately, it’s not working like it’s supposed to – the title doesn’t display. What’s wrong with my code?
function show_title_on_dashboard() {
$newest_post_id = $post[0]->ID;
$title = $newest_post_id->post_title;
echo "Latest Post: $title";
}
add_action("admin_notices", "show_title_on_dashboard");
You’re getting there! Couple of issues – you need to actually grab the latest posts before you can work on them. And
post_title
is not a property of the ID, but the object itself:Note: Ensure you have
define( 'WP_DEBUG', true )
in yourwp-config.php
when developing on WordPress – it will help immensely with debugging!