Created
December 15, 2017 19:14
-
-
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
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 | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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