---
title: "How to Search Posts by Custom Field in WordPress?"
url: https://nexterwp.com/docs/search-posts-by-custom-field-in-wordpress/
date: 2024-12-02
modified: 2026-04-14
author: "Aditya Sharma"
description: "Are you interested in searching posts using custom field data in WordPress? Custom fields let you add extra info to your posts, pages, products, or custom post types. Allowing users..."
image: https://nexterwp.com/wp-content/uploads/2024/12/How-to-Search-Posts-by-Custom-Field-in-WordPress_-1024x519.jpg
word_count: 408
---

# How to Search Posts by Custom Field in WordPress?

## Key Takeaways

- Nexter Blocks includes a Search Bar block that allows users to search any post type based on custom field data.
- Users must create at least one custom field using the free Advanced Custom Fields (ACF) plugin to enable searching by custom field data.
- The Search Bar block can be configured to search posts by location names after setting up the custom fields.

Are you interested in searching posts using custom field data in WordPress? Custom fields let you add extra info to your posts, pages, products, or custom post types. Allowing users to search using this custom field data can significantly enhance the accuracy and relevance of search results.

With the Search Bar block from the Nexter Blocks, you can easily search any post type based on custom field data.

*To check the complete feature overview documentation of the Nexter Blocks Search Bar* block, [click here](https://nexterwp.com/docs/add-a-search-bar-in-wordpress/).

***Requirement  - This block is a part of the Nexter Blocks, make sure it's installed & activated to enjoy all its powers.***

[LIVE BLOCK LINK](https://nexterwp.com/nexter-blocks/builder/wordpress-ajax-search-bar/)

To do this, make sure you have created at least one custom field for any post type. You have to use the free[ Advanced Custom Fields (ACF)](https://wordpress.org/plugins/advanced-custom-fields/) to[ ](https://www.advancedcustomfields.com/resources/registering-a-custom-post-type/)create the custom field.

For instance, we’ll create a custom field called **location** for normal blog posts.

Then add the Search Bar block on the page or template and follow the steps -

### Create Custom Fields

Once you have the ACF plugin installed follow the steps - 

1. From the Dashboard, go to **ACF** > **Field Groups** and click on **Add New** button. 

2. Add a name to the field group.

3. Then add a field type and add a name. For instance, we’ll add a checkbox field with the name called Location.

4. Once done, from the **Settings** section set the location to Post under **Rules**.

![](https://nexterwp.com/wp-content/uploads/2024/12/searchbar-custom-post-type-post.png)

5. Then click on the **Save Changes** button.

6. After that, you have to add value in the custom fields on some posts.

![](https://nexterwp.com/wp-content/uploads/2024/12/searchbar-custom-post-type-post-editor.png)

### Use the Search Bar Block

Then add the Search Bar block on the page or template.

1. Open the item under **Search Bar** and select **Post** from the **Source** section.

2. From the **Select Post** dropdown, select **Posts**.

Now, you should be able to see a dropdown beside the search bar.

Then make the necessary changes to Label, Placeholder and Show Count sections.

3. After that, go to the **Standard Search** tab and click on the wrench icon of **ACF Filters**.

4. Then in the **ACF Key** field, you have to add the custom field name.

To find the field name in ACF, edit the field group there you will find the field name.

![](https://nexterwp.com/wp-content/uploads/2024/12/searchbar-custom-post-type-post-location.png)

![](https://nexterwp.com/wp-content/uploads/2024/12/searchbar-acf-filters.gif)

Now, you’ll be able to search posts by location names.

In a similar way, you can search pages, products, or custom post types by custom field data.

## Frequently Asked Questions

**Q: What if my custom fields are not showing up in the search results?**
A: If your custom fields aren't appearing in search results, ensure you've correctly added values to those fields in your posts. After creating your custom fields using the Advanced Custom Fields (ACF) plugin, you need to populate them with data for them to be searchable. If they remain empty, the Search Bar block won't return any results based on those fields.

**Q: What is the best way to set up custom fields for accurate searches?**
A: To ensure accurate searches, create descriptive custom fields using the ACF plugin, such as 'Location' for geographical data. When setting up the Search Bar block, make sure to link it to the correct custom field name in the ACF Key field. This practice helps users find specific posts based on the criteria you define.

**Q: How do I create a custom field using the ACF plugin?**
A: To create a custom field with the ACF plugin, navigate to ACF &gt; Field Groups in your WordPress dashboard. Click 'Add New', name your field group, and then add a field type and name, such as a checkbox for 'Location'. Set the location rules to 'Post' and save your changes. This setup allows you to add specific data to your posts.

**Q: What happens if I forget to set the location rules for my custom fields?**
A: If you forget to set the location rules for your custom fields, they won't be associated with any posts, making them invisible in the WordPress editor. This means you won't be able to add values to those fields, and consequently, the Search Bar block won't be able to search based on them. Always ensure your rules are correctly configured.
