Hi
I am using a code snippet I found on Toolset's forum to count taxonomy for a post.
The code is below this used to work but since updates either by Toolset or WordPress itself it no longer works:
function count_post_terms( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'post_id' => '',
'taxonomy' => '',
),
$atts
);
$terms = wp_get_post_terms( $atts['post_id'], $atts['taxonomy']);
return count($terms);
}
add_shortcode( 'count_post_terms', 'count_post_terms' );
Here is where I am using the shortcode:
[wpv-conditional if="( [count_post_terms post_id='[wpv-post-id]' taxonomy='country'] gte 4 ) AND ( [count_post_terms post_id='[wpv-post-id]' taxonomy='country'] lt 40 )"]
<div class="tooltip">[count_post_terms post_id='[wpv-post-id]' taxonomy='country'] Countries<span class="tooltiptext">[wpv-post-taxonomy type="country" format="slug"]</span></div>
[/wpv-conditional]
[wpv-conditional if="( [count_post_terms post_id='[wpv-post-id]' taxonomy='country'] gte 40 )"]
<div class="tooltip">[count_post_terms post_id='[wpv-post-id]' taxonomy='country'] Countries<span class="tooltiptext">See Offer Page</span></div>
[/wpv-conditional]
When I debugged the results for when I used the above in a Toolset conditional it always give the result of 0.
Any ideas how we can fix?

Minesh
Unterstützer
Sprachen:
Englisch (English )
Zeitzone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Can you please make sure that the shortcode "count_post_terms " is registered at:
=> Toolset => Settings => Front-end Content tab => Third-party shortcode arguments
More info:
=> https://toolset.com/documentation/legacy-features/views-plugin/shortcodes-within-shortcodes/#third-party-shortcode-arguments
If the shortcode is already registered then I will require to debug and you will require to share information where you added the shortcode on what page/post, the link of problem URL and access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.

Minesh
Unterstützer
Sprachen:
Englisch (English )
Zeitzone:
Asia/Kolkata (GMT+05:30)
I've adjusted the shortcode you added as given under:
function count_post_terms( $atts ) {
global $post;
// Attributes
$atts = shortcode_atts(
array(
'post_id' => '',
'taxonomy' => '',
),
$atts
);
$terms = wp_get_object_terms( $post->ID, $atts['taxonomy']);
return count($terms);
}
add_shortcode( 'count_post_terms', 'count_post_terms' );
Can you please confirm now you can see the results as expected:
=> versteckter Link
Awesome thank you, all sorted.