Filter posts by checkboxes in wordpress (Custom fields from ACF)

Filter posts by checkbox acf wordpress and ajax

As we discussed this in our earlier posts that in WordPress, sometimes we needs to filter the posts. We had done with the filter posts by taxonomy. You can have a look at that tutorial from here. In this tutorial, we will continue to work on the filter. We will “filter posts by checkboxes in WordPress”. The most important part is that we will make the checkbox by using the ACF plugin. If you are familiar with ACF plugin then you can download the plugin from WordPress repository for ACF Plugin.

Now follow these step:

Step 1 – Create the Checkbox

First of all, create the field with type checkbox using ACF plugin. We will use these checkbox data in the filtering process.

Step 2 – Render the checkbox on frontend

Insert the code below into your template file. This code will call the checkbox in the frontend that we created with the ACF plugin.

Step 3 – Call the ajax

We have completed the view section. With the code above, your template is complete with the UI. The next step is to make the code work by calling the ajax with jquery. Copy and paste the following code into the footer.php file

Step 4 – Create ajax callback

In the above code, we had called an ajax function “get_keyword_data” . Now we have to make that function into the function.php file of your theme folder.

Filter posts by checkboxes

The above tutorial teach us about the Filter posts by checkboxes in WordPress which is very useful for those who work as WordPress developer.

Loading