Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Created March 2, 2021 03:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/b3d667b349fd03bbc0b1a1bab05258aa to your computer and use it in GitHub Desktop.
Save ipokkel/b3d667b349fd03bbc0b1a1bab05258aa to your computer and use it in GitHub Desktop.
Shortcode to display a series' list of articles with their available date. #pmpro_series #shortcode
<?php
/**
* This recipe creates a shortcode that shows the list of articles for a specific series.
* Use [pmpro_series id="n"] on any page/post to display a list of posts that belong to a series.
* The attribute "id" is the post ID of the series and is required, e.g [pmpro_series id="123"]
*
* This recipe assumes the site has the PMPro Series: Drip Feed Add On active.
* @link https://www.paidmembershipspro.com/add-ons/pmpro-series-for-drip-feed-content/
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_series_shortcode( $atts ) {
if ( ! function_exists( 'pmpros_the_content' ) ) {
return false;
}
global $post;
extract(
shortcode_atts(
array(
'id' => $post->ID,
),
$atts
)
);
//start output buffering
ob_start();
$series = new PMProSeries( $id );
$series->getPostList( true ); //true echoes post list
$temp_content = ob_get_contents();
ob_end_clean();
return $temp_content;
}
add_shortcode( 'pmpro_series', 'my_pmpro_series_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment