I have a homepage that is mixing two post-types : post and events
My aim is to print the details of each event in order to differentiate the content.
This is the method that I used to mix posts and events inside the Loop :
// The Query
$args = array(
'post_type' => array( 'post', 'event', 'book' )
);
$query = new WP_Query( $args );
In the Loop, I am printing the title, the excerpt and I wonder if it is possible then to introduce a condition (inside the Loop) to verify of this is an event and then retrieve some details about it. It looks exactly like this:
// The Loop
if ( $query->have_posts() ) : ?>
<?php if ( is_home() && ! is_front_page() ) : ?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php endif; ?>
<?php
// Start the loop.
while ( $query->have_posts() ) :
$query->the_post();
/*
* Instead of publishing all the content, on home page we only get the title, the thumbnail and an excerpt
*/
the_title( '<h1 class="entry-title">', '</h1>' );
the_excerpt() ;
// Test if this is an event and then print details
if (is_singular('event') ) {
eo_get_template_part( 'event-meta', 'event-single' );
}
// End the loop.
endwhile;
I am not really sure that I am using the best approach on this. I have seen that there is also another way to mix contents by modifying the global query in functions.php
Someone here can please tell me how can accomplish this ?
is_singular
and other conditionals always refer to the current global query, not custom queries. It will only return true if you're on the page of an event post, regardless of the type of the current post in the loop