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

Show custom post type on post category page doesn’t work / breaks navigation

The reason the menu is disappearing is because pre_get_posts applies to all queries on the page, including menus, your code is interferring with the menu queries. The is_main_query method should make sure it only affect the query in the loop, which in most cases will be the query displaying the posts. function test_add_cpt_to_archive_page( $query ) … Read more