The Custom Facebook Feed plugin has a filtering feature built into it which allows you to filter your posts by a specific string, word, or hashtag. You can set this for your feed by going to Facebook Feed > All Feeds > select Edit for the relevant feed > Settings > Filters.
Here, you can edit the filtration settings for your feed.
If you are not seeing all the expected results after filtration
It’s important to note that this filtering occurs after the posts have been returned from Facebook, as their API doesn’t allow us to request posts that contain only certain keywords, and so you would need to set the number of posts to be high enough that a larger batch of posts is retrieved from Facebook. This then gives the plugin more posts to filter through in order to find ones that contain your word/hashtag. You can adjust the number of posts that the plugin requests from Facebook’s API by using the ‘Post Limit’ setting, found in the feed options > Settings > Advanced. You can adjust this to a maximum of 100, as this is the limit of the Facebook API. It is advised not to set it higher than what is needed as you will end up requesting more posts than you need to display, increasing initial page load time.
If you’d like to remove the hashtag from your post so that it isn’t visible, then you can add the following JavaScript to your site. This can be done manually using a custom JavaScript plugin. For further information see our documentation here.
$('.cff-item').each(function(){
$(this).find('.cff-text').html( $(this).find('.cff-text').html().replace("#put_hashtag_here", "") );
});
You would need to replace the “#put_hashtag_here” with your actual hashtag. Important: This is case-sensitive.
Filtering by multiple keywords
You can specify multiple keywords using the plugin’s Filter feature by separating the keywords by commas, however, this setting works similar to an OR operator, rather than an AND operator, and so will display posts that contain any of the specified keyword
The Custom Facebook Feed plugin has a post filtering feature built into it which allows you to filter your posts by a specific string or hashtag. You can set this for all feeds by using the setting on the plugin’s Customize page in the following location: Facebook Feed > Customize > General > Filter Content by String. To set a filter for an individual feed, simply use the “filter” shortcode option, like so: [custom-facebook-feed filter="#hello"]
.
It’s important to note that this filtering occurs after the posts have been returned from Facebook, as their API doesn’t allow us to request posts which contain only certain keywords, and so you would need to set the number of posts to be high enough that a larger batch of posts is retrieved from Facebook. This then gives the plugin more posts to filter through in order to find ones which contain your word/hashtag. You can adjust the number of posts that the plugin requests from Facebook’s API by using the ‘Post Limit’ setting, which is on the plugin’s main Settings page, or you can set it individually in each shortcode by using the ‘limit’ setting, like so: [custom-facebook-feed limit=30]
. The maximum number of posts you can retrieve from Facebook per shortcode is 100, as this is the limit of their API. It is advised not to set it higher than is needed as you will end up requested more posts than you need to display.
If you’d like to remove the hashtag from your post so that it isn’t visible, then you can add the following to the plugin’s “Custom JavaScript” section (Customize > Misc > Custom JavaScript):
$('.cff-item').each(function(){
$(this).find('.cff-text').html( $(this).find('.cff-text').html().replace("#put_hashtag_here", "") );
});
You would need to replace the “#put_hashtag_here” with your actual hashtag. Important: This is case-sensitive.
Filtering by multiple keywords
You can specify multiple keywords using the plugin’s “Filter” feature by separating the keywords by commas, however, this setting works similar to an OR operator, rather than an AND operator, and so will display posts which contain any of the specified keywords, not posts which only contain all of them. However, it is possible to filter the posts a second time using JavaScript so that only posts which contain two words or hashtags are shown. To achieve this, you would do the following:
1) Set the filter in the shortcode: [custom-facebook-feed filter="word1"]
2) Add a class to the shortcode so that we can target it uniquely in the JavaScript snippet: [custom-facebook-feed filter="word1" class="feed1"]
3) Add the following to the plugin’s Custom JavaScript setting (Customize > Misc > Custom JavaScript):
$('.feed1 .cff-item').each(function(){
if( $(this).find('.cff-text').text().toLowerCase().indexOf("word2") < 0 ) $(this).remove();
});
This JavaScript snippet should loop through all of the posts which are in your feed and remove those which don’t contain the string “word2”. Note that you have to include the class of the feed you are targeting in the first line of the snippet.
You can then repeat this for the other feeds by duplicating the JavaScript snippet and changing the class and word in the snippet.