2

I'm using Simplenews Scheduler to automatically send a digest of new nodes, by inserting a views token into Body field of the newsletter.

I need to prevent sending the newsletter if the View in question is empty (triggers No results).

Simplenews Scheduler allows for PHP evaluation (see at the bottom of the screenshot):

Simplenews Scheduler options

What do I need to enter there to ensure no new newsletter is created and sent if a certain view (with certain exposed filter or contextual filters options) has no results?

1

I believe this will do:

!empty(views_get_view_result('your_views_machine_name','your_display_id'));

If you need to pass arguments, you can pass them as individual strings after the display id. See the API documentation. I'm not sure if you can pass exposed filter arguments, though (the above would work fine for contextual filter arguments).

  • Thank you! I do need to pass 2 arguments, the first one is a category and the second one is US states list and can be multivalue. My corresponding views token can be: [view:my_views_machine_name=page_3=$arg1/IL+TX] Should my code then be !empty(views_get_view_result('my_views_machine_name','page_3','Category-1','IL+TX')); ? – prkos Nov 17 '15 at 1:45
  • As far as I know the arguments after display_id are passed to the view the same way Contextual Filters are passed through the path of the view. Thus, IF your view works fine (and produces the desired results) by calling it through its path as in www.example.com/view_path/Category-1/IL+TX then it should work by using views_get_view_result() with CAtegory-1 and IL+TX as the 3rd and 4th arguments. – argiepiano Nov 17 '15 at 2:29
  • I haven't tested it with Scheduler yet, but I did test the PHP in a node body with if - print and it seems to be working, with arguments. Thank you! – prkos Nov 18 '15 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.