Upstatement/stream-manager

URL parameters to update Stream

Closed this issue · 3 comments

vilav commented

Hello,

Is there a way to make the stream manager more dynamic so it can showcase a specific set of posts or show the top 5 posts of a category by passing in URL parameters (like wordpress category /, required post IDs)?

In other words, abc.com?streamCat=categoryX?streamLinks=5 would show the stream manager with the top 5 posts of category X.

Similarly abc.com?streamID=33,44,55 would show the stream manager with posts w/ post ids 33,44 and 55

Would help deliver a more granular experience to users based on the link they click through therefore adding the opportunity to surface more content

Thanks!

Hi @vilav. Would you mind giving a little bit more detail about the use case you're describing? Is the goal to take an existing stream and return different filtered versions based on specified query params?

If the issue is more about creating distinct streams based on custom query parameters, the stream-manager/options/{stream-slug} filter (more info in the readme) may be what you're after.

vilav commented

Hi @lggorman bingo! that's a much better articulation. Both sound like great options! Taking an existing stream and filtering it based on query params is what I had in mind. The one you bring up creating distinct ones is an equally exciting prospect! what the best way to accomplish these?

@vilav For the first case, you should be able to pass additional query params to the stream->get_posts function.

$stream = new TimberStream('homepage');
$posts = $stream->get_posts(array('category_name' => 'athletics'));

To create a stream that only pulls posts from a certain post type or category (or really any other criteria you can query by), put something like this into your functions.php file, where homepage is replaced by the slug identifying the stream you want to target.

add_filter('stream-manager/options/homepage', function($defaults) {
  $defaults['query'] = array_merge($defaults['query'], array('category_name' => 'local-news'));
  return $defaults;
}); 

Hope this is helpful, and let me know if I can provide any further clarification!