Last active
August 1, 2025 09:23
-
-
Save nicmare/a360a38e094941c4f71f212463b04d83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* usage: | |
| ** [blocksy_search] | |
| ** [blocksy_search placeholder="Try the Search"] | |
| ** [blocksy_search post_type="locations" height="60px"] | |
| ** [blocksy_search no_liveresults="true" fontsize="22px" padding="20px"] | |
| */ | |
| function blocksy_search($args, $content){ | |
| if(!function_exists("blocksy_isolated_get_search_form")) return ""; | |
| $args = wp_parse_args($args); | |
| if(!empty($args["post_type"])){ | |
| $pts = [$args["post_type"]]; | |
| if(str_contains($args["post_type"],",")) | |
| $pts = explode(",",$args["post_type"]); | |
| if(str_contains($args["post_type"],";")) | |
| $pts = explode(";",$args["post_type"]); | |
| } | |
| $live_results = !empty($args["no_liveresults"])?"no":"yes"; | |
| $placeholder = !empty($args["placeholder"])?$args["placeholder"]:__('Search', 'blocksy'); | |
| $css_props = []; | |
| if(!empty($args["fontsize"])) | |
| $css_props["fontsize"] = sprintf("--form-font-size:%s",$args["fontsize"]); | |
| if(!empty($args["height"])) | |
| $css_props["height"] = sprintf("--form-field-height:%s",$args["height"]); | |
| if(!empty($args["padding"])) | |
| $css_props["padding"] = sprintf("--form-field-padding:%s",$args["padding"]); | |
| ob_start(); | |
| blocksy_isolated_get_search_form([ | |
| 'ct_post_type' => $pts??["post","page"], | |
| 'search_live_results' => $live_results, | |
| 'live_results_attr' => 'thumbs', // no | |
| 'search_placeholder' => $placeholder | |
| ]); | |
| $content = ob_get_contents(); | |
| ob_get_clean(); | |
| return sprintf("<div%s>%s</div>",!empty($css_props)?sprintf(' style="%s"',implode(";",$css_props)):"",$content); | |
| } | |
| add_shortcode("blocksy_search",'blocksy_search'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment