I am using this code in a page template to determine the custom post type and display a different template for each custom post type.
if ( $query->have_posts() )
{
?>
<ul id="floros">
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<?php
$curtype = get_post_type( $post->ID );
switch ($curtype) {
case "events":
?>
<?php
break;
case "brands":
?>
..etc
However i have an issue with this line: $curtype = get_post_type( $post->ID );
Trying to get property 'ID' of non-object in search-filter/results.php on line 37
PHP Notice: Undefined variable: post in search-filter/results.php on line 37
The page shows results as expected, however the debug log is filled with duplicated lines of the above. I suppose I need to somehow check only for the type of the first object to avoid this error?