Recently, we ran into a problem where we needed the ability to exclude certain KingSumo giveaways that were running from showing up on a primary giveaway rotator we had created. This sounded like a simple enough job – our initial thought was that we could just exclude the ‘X’ category from the slider. However, we found that by default, KingSumo does not support categories or tags.
The last thing we wanted to do was modify the giveaway plugin itself, as that would have required us to re-patch it every update. We also did not want to create a manual array with the post IDs we wanted to exclude. So, we set out to find a way to use the least modifications necessary to get the exclusion up and running, as well as make it as user-friendly as possible.
Our first task was to see how we could add the categories field to the KingSumo system setup, which is a custom post type. However, we wanted to avoid modifying the plugin itself, as we did not want to have to make the same change with every update. The solution was to hook the existing custom post type with our own.
We then added the category taxonomy, but found that once a category was added, there was no way to remove it (or even see it in some places). This was because the post terms were not saved when categories were added or removed from individual giveaways, and our goal was simplicity with steps that anyone could replicate across any site. We kept the hook (since we had a couple of other uses for it) but removed the category taxonomy.
Enter the Advanced Custom Fields plugin by Elliot Condon. This plugin would allow not only us but future site developers (at any skill level) to make quick and easy changes to the custom post type, all without coding. Best of all, saving the terms to the post was as simple and easy as checking a single box.
First, we created a new Field Group within the ACF plugin options. Inside this newly created Field Group, we started inserting options that would be used with the editor of the giveaway itself. (* Make sure to select “Load & Save Terms to Post” to save the options you select to the post.)”
Just below, we set the rules for where these new options would show up. We set up the categories options (mentioned above) to display only if the post type was equal to our giveaway post type.
This is how the newly created options appear within the individual giveaway.
We then had to find the category ID of the category we had just created – this could be found under Posts -> and Categories. If you hover over the category the category name on the bottom of the screen you’ll see category&tag_ID=XXX , you will need the tag_ID number, this is what we will add to our slider loop to exclude.
The last thing we had to do was pass the category exclusion to the rotator in our list of arguments. This was done by adding ‘category__not_in’ => (Insert tag_ID number)
We then checked out the rotator, tested the exclusion by adding / removing giveaways to the rotator and didn’t have a single issue.