Created
January 15, 2020 21:05
-
-
Save itsjusteileen/9bb22b7d990c2d4be0cff32818137126 to your computer and use it in GitHub Desktop.
Lists all SSP plugin podcast custom post type on the home page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: SSP Customizations | |
Plugin URI: https://github.com/TheCraigHewitt/Seriously-Simple-Podcasting | |
Description: Customizations for the Seriously Simple Podcasting Plugin | |
Version: .1 | |
Author: itsjusteileen | |
Author URI: https://github.com/itsjusteileen | |
*/ | |
/* | |
Displays SSP custom post type PODCAST archive as the home page. Amended from https://www.gmitropapas.com/set-a-custom-category-post-type-archive-as-your-homepage/ | |
*/ | |
function ssp_podcast_front_page( $query ) { | |
// Only filter the main query on the front-end | |
if ( is_admin() || ! $query->is_main_query() ) { | |
return; | |
} | |
global $wp; | |
$front = false; | |
// If the latest posts are showing on the home page | |
if ( ( is_home() && empty( $wp->query_string ) ) ) { | |
$front = true; | |
} | |
// If a static page is set as the home page | |
if ( ( $query->get( 'page_id' ) == get_option( 'page_on_front' ) && get_option( 'page_on_front' ) ) || empty( $wp->query_string ) ) { | |
$front = true; | |
} | |
if ( $front ) : | |
$query->set( 'post_type', 'podcast' ); | |
$query->set( 'page_id', '' ); | |
// Set properties to match an archive | |
$query->is_page = 0; | |
$query->is_singular = 0; | |
$query->is_post_type_archive = 1; | |
$query->is_archive = 1; | |
endif; | |
// Fix pagination | |
if ( get_query_var( 'paged' ) ) { | |
$paged = get_query_var( 'paged' ); | |
} elseif ( get_query_var( 'page' ) ) { | |
$paged = get_query_var( 'page' ); | |
} else { | |
$paged = 1; | |
} | |
$query->set( 'paged', $paged ); | |
} | |
add_action( 'pre_get_posts', 'ssp_podcast_front_page' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment