Is it possible to add settings to a search block in Gutenberg?

admin2025-01-07  9

I'm getting back into WordPress development again, but noticed a lot of things have changed but want to take advantage of any new efficient methods that exist in the Gutenberg system.

I want to create a custom search that only queries custom post types. When I switch to the code editor mode, I noticed I might be able to add more settings. This is what I see:

<div class="wp-block-group">
<!-- wp:search {"label":"Search","showLabel":false,"buttonText":"Search","buttonPosition":"button-inside","buttonUseIcon":true} /-->
</div>

Are there any settings I can add to this wp:search line that would let me isolate querying a custom post type only?

I'm getting back into WordPress development again, but noticed a lot of things have changed but want to take advantage of any new efficient methods that exist in the Gutenberg system.

I want to create a custom search that only queries custom post types. When I switch to the code editor mode, I noticed I might be able to add more settings. This is what I see:

<div class="wp-block-group">
<!-- wp:search {"label":"Search","showLabel":false,"buttonText":"Search","buttonPosition":"button-inside","buttonUseIcon":true} /-->
</div>

Are there any settings I can add to this wp:search line that would let me isolate querying a custom post type only?

Share Improve this question asked Dec 20, 2024 at 18:05 Marc PMarc P 5351 gold badge5 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You can try adjusting the post type of the search query with:

<!-- wp:search {
    "label":"Search",
    "buttonText":"Search", 
    "query" : {"post_type" : "cpt"} 
} /-->

replacing cpt with your custom post type.

This will add a hidden input tag, to the search form, for the post_type GET query parameter.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736257921a474.html

最新回复(0)