Replies: 0
I am trying to realise a little script in the header, which should show a different message depending if there is a new post or a new custom post published.
What I have so far:
$args = array( 'numberposts' => '1', 'post_status' => 'publish' );
$args_talks = array( 'numberposts' => '1', 'post_type' => array('talks', 'post'), 'post_status' => 'publish' );
$recent_posts = wp_get_recent_posts( $args_talks );
foreach( $recent_posts as $recent ){
if ( 'rtalks' === get_post_type() ) {
echo "Latest Talk from '. get_the_date('d F Y', $recent["ID"]) .':<br/><a href="' . get_permalink($recent["ID"]) . '">'. get_the_title( $recent["ID"] ) .'</a>'";
} else {
echo 'Latest News from '. get_the_date('d F Y', $recent["ID"]) .':<br/><a href="' . get_permalink($recent["ID"]) . '">'. get_the_title( $recent["ID"] ) .'</a>';
}
}
I am aware that the last “if else” part is wrong, but it should illustrate what I am trying to achieve. Or maybe I’m doing something fundamentally wrong.
In any case I would be grateful for any help!