Skip to content
  • Features
  • Demo
    • Default Archive
    • Custom Archive
    • All Series
    • Single Sermon
    • Single Series
    • Single Speaker
    • Shortcodes
    • Archive Shortcode
    • List & Grid View
  • Pricing
  • Addons
    • Campus Addon | 1.1
    • Service Type Addon | 1.1
  • Resources
    • Documentation
    • Blog
    • Changelog
  • Help
    • Getting Started
    • Import Sermons
    • FAQ’s
    • Feature Requests
    • Roadmap
    • Support
    • Account
Try Demo
Purchase

Getting Started

13
  • Download & Installation
  • Activate & Manage Your License
  • Save Permalinks
  • Taxonomy Drag & Drop Ordering
  • Add & Manage Sermons
  • Add & Manage Speakers
  • Add & Manage Series
  • Add & Manage Topics
  • General Settings
  • Archive Settings
  • Single Sermon Settings
  • Design Settings
  • Shortcode Settings

FAQ's

7
  • Import Sermons
  • Translate Advanced Sermons
  • Customize Archive & Single Sermon Template
  • How to use Block Editor on Sermons
  • Advanced Sermons Podcasting
  • Refund Policy
  • Do you offer a lifetime license

Troubleshooting

3
  • Advanced Sermons Pro: Download Not Available
  • Download Failed: Unauthorized
  • Sermons Returning 404 Error

Developers

4
  • Customize Archive & Single Sermon Template
  • Hooks & Filters
  • Add Custom Taxonomies to Advanced Sermons
  • How to create a custom extension
View Categories
  • Home
  • Docs
  • Developers
  • Add Custom Taxonomies to Advanced Sermons

Add Custom Taxonomies to Advanced Sermons

Advanced Sermons
Updated on November 17, 2024

How To Add Custom Taxonomies to Advanced Sermons #

Summary

In this online documentation, we’ll guide you on how to add custom taxonomies to Advanced Sermons. The method has undergone changes with the introduction of Advanced Sermons 3.0. This guide is intended to help those who had created custom taxonomies prior to the release of Advanced Sermons 3.0 and want to integrate them into the updated version.

 

Option 1. Download & Install Advanced Sermons Taxonomy Addons

For a streamlined experience, we’ve crafted custom taxonomy plugins that are ready for download and installation on your WordPress site. Once activated, no further steps are required. The new taxonomy will be visible under the dashboard menu item ‘Sermons’. Assign a sermon to the taxonomy, and it will be displayed on the frontend in the filter bar, grid view, list view, and individual sermon template. To ensure the proper functioning of these addons, please ensure that you’ve updated Advanced Sermons to version 3.0.

Campus Addon | 1.1Service Type Addon | 1.1

 

Option 2. Add and Customize Your Own Code

For developers who prefer a hands-on approach to integrating customizations, use the code provided below. Add this to your own plugin or the functions.php file of your child theme. This code works seamlessly with all the built-in hooks available in Advanced Sermons.

 

// Create custom sermon campus taxonomy
add_action('init', 'asp_register_taxes_campus');
function asp_register_taxes_campus() {
    // Get Advanced Sermons global variables
    global $asp_archive_slug;

    $labels = array(
        "name" => __("Campuses", "advanced-sermons"),
        "singular_name" => __("Campuses", "advanced-sermons"),
        "menu_name" => __("Campuses", "advanced-sermons"),
        "search_items" => __("Search Campuses", "advanced-sermons"),
        "popular_items" => __("Most popular Campuses", "advanced-sermons"),
        "all_items" => __("All  Campuses", "advanced-sermons"),
        "edit_item" => __("Edit  Campuses", "advanced-sermons"),
        "update_item" => __("Update  Campuses", "advanced-sermons"),
        "add_new" => __("Add New  Campuses", "advanced-sermons"),
        "add_new_item" => __("Add New  Campuses", "advanced-sermons"),
        'view_item' => __("View  Campuses", "advanced-sermons"),
        'parent_item' => null,
        'parent_item_colon' => null,
    );
    $args = array(
        "label" => __("Campuses", "advanced-sermons"),
        "labels" => $labels,
        "public" => true,
        "hierarchical" => true,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => false,
        "query_var" => true,
        "has_archive" => true,
        "rewrite" => array("slug" => "/$asp_archive_slug/", "with_front" => false),
        "show_admin_column" => true,
        "show_in_rest" => false,
        "show_in_quick_edit" => true,
    );
    register_taxonomy("sermon_campus", array("sermons"), $args);
}

// Archive Filter Dropdown Campus. Utilizing Hook from documentation.
add_action( 'asp_hook_filter_bar_fields', 'asp_archive_filter_campus', 110 );
function asp_archive_filter_campus() {
    $taxonomies = array( 'sermon_campus' );
    $args = array( "orderby" => "name", "hide_empty" => true, "order" => "ASC" );
    asp_filter_terms_dropdown_campus($taxonomies, $args);
}


// Dynamically populate campus data into sermon archive filter
function asp_filter_terms_dropdown_campus($taxonomies, $args) {
    $asp_archive_filter_sermon_count = get_option('asp_archive_filter_sermon_count');
    $asp_campus_terms = get_terms($taxonomies, $args);
    echo '<div class="sermon-field-container topic-container">';
    echo "<select name='sermon_campus' class='asp-filter-topic'>";
    echo '<option value="">' . __("All Campuses", "advanced-sermons") . '</option>';

    foreach ($asp_campus_terms as $term) {
        $term_slug = $term->slug;
        $term_name = $term->name;
        if (empty($asp_archive_filter_sermon_count)) {
            $term_count = "($term->count)";
        } else {
            $term_count = null;
        }
        $link = $term_slug;
        if (!empty($_REQUEST['sermon_campus'])) {
            echo "<option " . selected($_REQUEST['sermon_campus'],
                    $link) . " value='$link'>$term_name $term_count</option>";
        } else {
            echo "<option value='$link'>$term_name $term_count</option>";
        }
    }
    echo "</select>";
    echo "</div>";
}


// Front page sort by menu_order for archive page
add_filter( 'asp_allowed_taxonomies_filter', function( $taxonomies ) {
   $taxonomies[] = 'sermon_campus';

   return $taxonomies;
} );


// Checks if the campus taxonomy is selected in the filter
add_filter('asp_filter_selected_taxonomy', 'asp_is_campus_selected');
function asp_is_campus_selected($asp_filter_selected_taxonomy) {
    $selected_campus = $_REQUEST['sermon_campus'] ?? '';

    // If any other criteria is selected or if the campus is selected, return true.
    return $asp_filter_selected_taxonomy || !empty($selected_campus);
}

// Add selected campus to criteria box results
add_filter('asp_custom_filter_criteria', 'asp_add_campus_filter_criteria');
function asp_add_campus_filter_criteria($html) {
    $sermon_campus = $_REQUEST['sermon_campus'] ?? '';

    if (!empty($sermon_campus)) {
        $selected_campus_slug = get_term_by('slug', "$sermon_campus", 'sermon_campus');
        $selected_campus_name = $selected_campus_slug->name;
        $html .= "<p class='asp-selected-campus'>" . __("Campus", "advanced-sermons") . ": " . __("$selected_campus_name", "advanced-sermons") . "</p>";
    }

    return $html;
}


// Add campus taxonomy data to sermon details on grid view, list view, and single sermon templates
function asp_sermon_header_details_campus() {
    global $post, $asp_archive_slug;
    $asp_sermon_campus = wp_get_post_terms($post->ID, 'sermon_campus', array("fields" => "names"));
    $asp_sermon_campus_slug = wp_get_post_terms($post->ID, 'sermon_campus', array("fields" => "slugs"));

    if (isset($asp_sermon_campus[0])) { ?>
        <div class='sermon-campus'><p>
                <?php _e('Campus', 'advanced-sermons'); ?>:
                <?php
                $count = count($asp_sermon_campus);
                $i = 0;
                foreach ($asp_sermon_campus as $index => $campus) {
                    $i++;

                    if (get_option('permalink_structure')) {
                      echo "<a href='" . get_home_url() . "/" . $asp_archive_slug . "/?sermon_campus=" . $asp_sermon_campus_slug[$index] . "'>" . $campus . "</a>";
                    } else {
                      echo "<a href='" . get_home_url() . "/?post_type=sermons&sermon_campus=" . $asp_sermon_campus_slug[$index] . "'>" . $campus . "</a>";
                    }
                    
                    if ($i < $count) {
                        echo ", ";
                    }
                }
                ?>
            </p></div>
    <?php }
}
add_action('asp_hook_sermon_archive_header_details', 'asp_sermon_header_details_campus');
add_action('asp_hook_sermon_single_header_details', 'asp_sermon_header_details_campus');
Updated on November 17, 2024
Hooks & FiltersHow to create a custom extension
Table of Contents
  • How To Add Custom Taxonomies to Advanced Sermons
Share This Article :
  • Facebook
  • X
  • LinkedIn
  • Pinterest
Was it helpful ?
  • Happy
  • Normal
  • Sad

Advanced Sermons is a new beautiful, modern sermon plugin that integrates seamlessly with any WordPress theme.

Quick Links

  • Demo
  • Features
  • Pricing
  • Documentation
  • Changelog

WP Codeus

  • About Us
  • Plugins
  • Blog
  • Contact

Get Support

  • Get Started
  • FAQ/Troubleshooting
  • Support
  • Account

Copyright © 2025 Advanced Sermons. All rights reserved.

  • Proudly developed by WP CodeUs