taxonomy. * * @return array */ function fegp_filter_map() { return array( 'prediger' => 'sermon_speaker', 'thema' => 'sermon_topics', 'buch' => 'sermon_book', 'gruppe' => 'feg_topic_group', ); } /** * Current filter values from the URL (public, read-only GET filters; no nonce needed). * * @return array */ function fegp_current_filters() { $out = array(); foreach ( fegp_filter_map() as $arg => $tax ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only public archive filter. $out[ $arg ] = isset( $_GET[ $arg ] ) ? sanitize_title( wp_unslash( $_GET[ $arg ] ) ) : ''; } return $out; } /** * Build tax_query from filters. * * @return array */ function fegp_tax_query() { $map = fegp_filter_map(); $tq = array(); foreach ( fegp_current_filters() as $arg => $val ) { if ( '' === $val ) { continue; } if ( 'gruppe' === $arg ) { $g = get_term_by( 'slug', $val, 'feg_topic_group' ); if ( ! $g ) { continue; } $ids = array_merge( array( $g->term_id ), get_term_children( $g->term_id, 'feg_topic_group' ) ); $topics = get_terms( array( 'taxonomy' => 'sermon_topics', 'hide_empty' => false, 'fields' => 'ids', 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Small term set. array( 'key' => 'fegp_group_id', 'value' => $ids, 'compare' => 'IN', ), ), ) ); $or = array( 'relation' => 'OR', array( 'taxonomy' => 'feg_topic_group', 'terms' => $ids, ), ); if ( $topics && ! is_wp_error( $topics ) ) { $or[] = array( 'taxonomy' => 'sermon_topics', 'terms' => $topics, ); } $tq[] = $or; } else { $tq[] = array( 'taxonomy' => $map[ $arg ], 'field' => 'slug', 'terms' => $val, ); } } return $tq; } /** * Apply filters and page size on the sermon archive main query. * * @param WP_Query $q Query. */ function fegp_pre_get_posts( $q ) { if ( is_admin() || ! $q->is_main_query() || ! $q->is_post_type_archive( 'sermons' ) ) { return; } $o = fegp_options(); $q->set( 'posts_per_page', (int) $o['per_page'] ); $tq = fegp_tax_query(); if ( $tq ) { $q->set( 'tax_query', $tq ); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Filtering is the purpose. } } add_action( 'pre_get_posts', 'fegp_pre_get_posts' ); /** * Use plugin templates on classic themes. * * @param string $template Template path. * @return string */ function fegp_template_include( $template ) { $o = fegp_options(); if ( ! $o['use_templates'] || ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) ) { return $template; } if ( is_singular( 'sermons' ) ) { $theme = locate_template( 'feg-predigten/single.php' ); return $theme ? $theme : FEGP_DIR . 'templates/single-sermons.php'; } if ( is_post_type_archive( 'sermons' ) || is_tax( array( 'sermon_speaker', 'sermon_topics', 'sermon_book', 'feg_topic_group' ) ) ) { $theme = locate_template( 'feg-predigten/archive.php' ); return $theme ? $theme : FEGP_DIR . 'templates/archive-sermons.php'; } return $template; } add_filter( 'template_include', 'fegp_template_include', 99 ); /** * Block themes: append details and player to the content. * * @param string $content Content. * @return string */ function fegp_content_filter( $content ) { if ( ! is_singular( 'sermons' ) || ! in_the_loop() || ! is_main_query() ) { return $content; } $o = fegp_options(); if ( $o['use_templates'] && ! ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) ) { return $content; } return fegp_meta_list( get_the_ID() ) . $content . '
' . esc_html__( 'No sermons found.', 'kanzelbuch' ) . '
'; } $html = '