admin管理员组文章数量:1404615
I'd like to list the taxonomy terms within my shortcode.
This is how I get the list of terms (separated by commas):
<?php $terms = get_the_terms( $post->ID , array( 'shoptype' ) );
$i = 1;
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, array( 'shoptype' ) );
if( is_wp_error( $term_link ) )
continue;
echo '' . $term->name . '';
echo ($i < count($terms))? ", " : "";
$i++;
} ?>
But I am trying to apply this to the following code (taxonomy_terms="' . $term->slug . '"), however it just keeps repeating the shortcode for each term:
<?php $terms = get_the_terms( $post->ID , 'shoptype' );
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, 'shoptype' );
if( is_wp_error( $term_link ) )
continue;
echo do_shortcode( '[ajax_load_more post_type="shops" taxonomy="shoptype" taxonomy_terms="' . $term->slug . '" taxonomy_operator="IN" posts_per_page="9" button_loading_label="Loading Shops" button_label="View More" scroll="false" repeater="default" orderby="title" order="ASC"]' );
}
?>
Is there a way to list the terms (separated by commas) in the taxonomy_terms="" section?
I'd like to list the taxonomy terms within my shortcode.
This is how I get the list of terms (separated by commas):
<?php $terms = get_the_terms( $post->ID , array( 'shoptype' ) );
$i = 1;
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, array( 'shoptype' ) );
if( is_wp_error( $term_link ) )
continue;
echo '' . $term->name . '';
echo ($i < count($terms))? ", " : "";
$i++;
} ?>
But I am trying to apply this to the following code (taxonomy_terms="' . $term->slug . '"), however it just keeps repeating the shortcode for each term:
<?php $terms = get_the_terms( $post->ID , 'shoptype' );
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, 'shoptype' );
if( is_wp_error( $term_link ) )
continue;
echo do_shortcode( '[ajax_load_more post_type="shops" taxonomy="shoptype" taxonomy_terms="' . $term->slug . '" taxonomy_operator="IN" posts_per_page="9" button_loading_label="Loading Shops" button_label="View More" scroll="false" repeater="default" orderby="title" order="ASC"]' );
}
?>
Is there a way to list the terms (separated by commas) in the taxonomy_terms="" section?
Share Improve this question asked Jan 15, 2020 at 0:20 rel_99rel_99 32 bronze badges1 Answer
Reset to default 2The do_shortcode()
function is currently in the foreach loop. I don't know what are the parameters of this shortcode , but if it accepts comma separated values of term slugs:
$terms = get_the_terms( $post->ID , 'shoptype' );
$i=1;
$commaSeparatedvalues="";
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, 'shoptype' );
if( is_wp_error( $term_link ) )
continue;
$commaSeparatedvalues .= $term->slug;
$commaSeparatedvalues .= $i < count($terms) ? ", " : "";
$i++;
}
echo do_shortcode( '[ajax_load_more post_type="shops" taxonomy="shoptype" taxonomy_terms="' . $commaSeparatedvalues . '" taxonomy_operator="IN" posts_per_page="9" button_loading_label="Loading Shops" button_label="View More" scroll="false" repeater="default" orderby="title" order="ASC"]' );
So basically build the comma separated string in the foreach
and keep the do_shortcode()
function out of the foreach loop
本文标签: phpList taxonomy term slugs within shortcode (doshortcode)
版权声明:本文标题:php - List taxonomy term slugs within shortcode (do_shortcode) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744835180a2627587.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论