You are here:  » Run Global Filters before and after feed filters


Run Global Filters before and after feed filters

Submitted by ChrisNBC on Mon, 2014-11-03 13:37 in

Hi David,

I wondered if you might be able to suggest if there is some way I can run two sets of global filters, so that one set of global filters runs as it does now before the feed filters but then a second (separate) set of global filters would run after the feed filters ? If it's complicated, I can just create feed filters but if it's straight forward to implement it would be a really useful function.

Thanks in advance.

Regards
Chris

Submitted by support on Tue, 2014-11-04 09:51

Hi Chris,

A new field could be added to global filters to indicate pre or post 'per feed' filters but I can think of a very easy work-around that would require just one simple change in the code.

Global filters are applied first because filters are loaded using an ORDER BY filename clause, global filters have a filename of '' and '' is always alphabetically first, so a work around would be to create a dummy (empty) feed with a filename that would always be alphabetically last, and then modify the code where filters are loaded to also load filters for the dummy feed.

To give this a go create a new dummy feed file:

feeds/zzGlobalAfter

...containing:

ProductName,BuyURL,Price

Register the feed using the manually select Format String "Text - Header Row - Comma Separated" and map fields ProductName, BuyURL and Price as normal, then just click Register.

Finally, edit includes/admin.php and look for this code at line 475:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($admin_importFeed["filename"])."' OR filename='' ORDER BY filename,created";

...and REPLACE with:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($admin_importFeed["filename"])."' OR filename='' OR filename='zzGlobalAfter' ORDER BY filename,created";

Then simply add filters to the zzGlobalAfter feed which will then be treated as global filters applied after per feed filters!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Fri, 2014-11-07 17:50

Hi David,

Thanks for the solution above. I have set it up exactly as described but the filters I have set appear to have no effect on the data.

Would be grateful if you could suggest what could be going wrong.

Thanks in advance.

Regards
Chris

Submitted by support on Fri, 2014-11-07 18:32

Hi Chris,

In order to register the dummy feed it will require a NULL row following the header row - have a go with, as feeds/zzGlobalAfter

ProductName,BuyURL,Price
,,,

(don't forget to add entries for any other fields you wish to add global after filters to)

Make sure zzGlobalAfter registered, imported and showing 0 products, then you should be able to attach filters to it, to be applied after per-feed filters.

Cheers,
David.
--
PriceTapestry.com