Skip to content

Instantly share code, notes, and snippets.

@nicmare
Last active August 1, 2025 09:23
Show Gist options
  • Select an option

  • Save nicmare/a360a38e094941c4f71f212463b04d83 to your computer and use it in GitHub Desktop.

Select an option

Save nicmare/a360a38e094941c4f71f212463b04d83 to your computer and use it in GitHub Desktop.
<?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