How to print different informations for different post types inside The Loop?

Of course, you can use conditions like this inside the loop. if ( ‘event’ == get_post_type( get_the_ID() ) ) { // do something } Full code would be // 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 … Read more

Custom post archive with search, is_search() is false?

Name your keyword input just s <input name=”s” type=”text” placeholder=”Filter by keyword” value=””/> This is enough for WP to recognize the request as search plus you won’t have to do the $query->set( ‘s’, … ) later In pre_get_posts action use the conditional is_post_type_archive( ‘document’ ) so your if statement look something like this: if ( … Read more

On archive.php show loop for child categories if they exist or posts if they don’t, on custom post type

This works, anything better would be appreciated $term = get_queried_object(); $term_id = $term->term_id; $taxonomy_name = $term->taxonomy; $termchildren = get_term_children( $term_id, $taxonomy_name ); if (!empty($termchildren)) { echo ‘<div class=”subcatwrapper”>’; echo ‘<ul class=”workshopgrid centerWidth”>’; foreach ( $termchildren as $child ) { $term = get_term_by( ‘id’, $child, $taxonomy_name ); echo ‘<li class=”workshopbox”>’; echo ‘<div class=”workshopimage”><a href=”‘. get_term_link( $term->slug, … Read more