Skip to content

Instantly share code, notes, and snippets.

@rafaehlers
Created December 15, 2017 19:14
Show Gist options
  • Save rafaehlers/7c8e843c725de528fcb04fec1d996d7f to your computer and use it in GitHub Desktop.
Save rafaehlers/7c8e843c725de528fcb04fec1d996d7f to your computer and use it in GitHub Desktop.
Custom Shortcode to split tag fields into links to use as a search parameter for a View in another page
<?php
add_shortcode( 'gv_tag', 'gv_tag_shortcode' );
function gv_tag_shortcode( $atts ) {
extract( shortcode_atts(
array(
'field' => '',
), $atts )
);
$links = "";
$tags = array_filter(explode(' ', $field), 'strlen');
foreach ($tags as $key => $value) {
$links .= '<span class="gv_tag"><a href="http://website.com/view/?filter_1='.$value.'">'.$value.'</a></span> ';
}
return $links;
}
@rafaehlers
Copy link
Author

Use inside a Custom Content field: [gv_tag field="{Post Tags:6}"] (make sure to use the correct Merge Tag of the Tag field from your own form

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment