Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

get_posts_in_series

part of GWP tutorial : https://generatewp.com/group-post-series-custom-taxonomy

	/*
	 * get_posts_in_series
	 * Get post ids of posts in a series by series ID 
	 * @param  int $series_id series term ID
	 * @return array|boolean  array of post IDs or false if none found 
	 */
	function get_posts_in_series( $series_id ){
		$args = array(
			//get both published and future posts (filterable)
			'post_status'    => apply_filters('GWP_series_post_status', array('publish','future') ),
			//number of posts to list (filterable)
			'posts_per_page' => apply_filters('GWP_series_post_limit', 8 ),
			//order by date
			'orderby'        => 'date',
			//Ascending order
			'order'          => 'ASC',
			//we only need the IDs of the posts
			'fields'         => 'ids',
			//tax query this is where we tell WordPress to select posts grouped by our taxonomy
			'tax_query'      => array(
				array(
					'taxonomy' => $this->tax_name, 
					'field'    => 'term_id', 
					'terms'    => $series_id
				)
			)
		);

		//select all posts in series
		$posts = new WP_Query( 
			apply_filters('GWP_series_get_posts_args', $args, $series_id ) //allow filtering of arguments 
		);

		//check if any posts were found
		if ( $posts->have_posts() ){
			//posts were found in the series so we return them
			return $posts->posts;
		}else{
			//no posts were found so we return false;
			return false;
		}
	}