I have this template file called Events. The purpose of this file is just to display the latest post with custom type Event. I have solved it with a very ugly solution. There must be a simpler and more correct way to do this. If you check my code im sure you understand what im trying to accomplish :)
Thanks in advance!
<?php
/*
* Template Name: Event
*/
?>
<?php
$permalink = get_permalink($wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_type = 'event' ORDER BY post_date DESC LIMIT 1"));
?>
<html>
<head>
<script type="text/javascript">
window.location = "<?php echo $permalink; ?>";
</script>
</head>
<body>
</body>
</html>
Cleaner solution:
<?php
/*
* Template Name: Event
*/
$permalink = get_permalink($wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_type = 'event' ORDER BY post_date DESC LIMIT 1"));
header('Location: '.$permalink);
?>