-
-
Save ipokkel/7ef7c13a2a3dd1cde4a174edb5ca8064 to your computer and use it in GitHub Desktop.
Adds a [my_pmpro_series] shortcode to display a specific series post list.
This file contains hidden or 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 | |
| /** | |
| * This recipe creates a [my_pmpro_series] shortcode | |
| * to display a specific series post list. | |
| * | |
| * This shortcode requires that a Series (Post) ID is provided. | |
| * | |
| * To obtain the Post ID for a series, from the | |
| * WordPress dashboard navigate to Series > Series, | |
| * click on the series name, in the edit page URL | |
| * the Post ID is querystring post, e.g if URL is | |
| * https://example.com/wp-admin/post.php?post=42&action=edit | |
| * the Post ID = 42 | |
| * | |
| * To display this series using the shortcode assign that value | |
| * to the "id" attribute, e.g. | |
| * [my_pmpro_series id="42"] | |
| * | |
| * 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 ) { | |
| // Bail if PMProSeries is not active. | |
| if ( ! class_exists( 'PMProSeries' ) ) { | |
| return false; | |
| } | |
| // Require that a Series was specified. | |
| if ( empty( $atts ) ) { | |
| 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( 'my_pmpro_series', 'my_pmpro_series_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment