---
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 Search Bar block searches any post type by custom field data, including posts, pages, products, and custom post types.
- ACF creates the custom field first by adding a field group, setting a field name such as Location, and assigning the location rule to Post.
- Search Bar block uses the Standard Search tab and the ACF Filters wrench icon, where the ACF Key field takes the custom field name to search posts by location names.

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.