Skip to content

Instantly share code, notes, and snippets.

@itsjusteileen
Created January 15, 2020 21:05
Show Gist options
  • Save itsjusteileen/9bb22b7d990c2d4be0cff32818137126 to your computer and use it in GitHub Desktop.
Save itsjusteileen/9bb22b7d990c2d4be0cff32818137126 to your computer and use it in GitHub Desktop.
Lists all SSP plugin podcast custom post type on the home page
<?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