I require assistance Nesting a Toolset Types Field in a Custom Shortcode.
A. This short-code works and returns the proper post count:
[taxonomy_term_post_count taxonomy="oranges"]
B. This short-code returns the correct value of "oranges"
[types field='fruit'][/types]
C. I would like to be able insert shortcode B as the parameter for shortcode A in the form of this "nested" shortcode:
[taxonomy_term_post_count taxonomy="[types field='fruit'][/types]"]
The code for my Shortcode snippet is here:
___________________
// Add Shortcode to show posts count of a taxonomy term
function taxonomy_term_post_count( $atts ) {
// get the taxonomy by slug.
$term = get_term_by( 'slug', $atts['taxonomy'], 'custom-taxonomy-slug');
return ( isset( $term->count ) ) ? $term->count : 0;
}
add_shortcode( 'taxonomy_term_post_count', 'taxonomy_term_post_count' );
___________________
The shortcode you would invoke is: [taxonomy_term_post_count taxonomy="taxonomy-term-slug"]. I would like to use a types field shortcode [types field='fruit'][/types] for my taxonomy-term-slug but when I do the nested shortcode does not return a value.
Can anyone guide me as to how I would need to modify my code snippet code to allow for nesting the Types Shortcode into my shortcode? Thanks!!!
If you can share problem URL confirm that you want to display the post count for the specific taxonomy term and access details I can review your setup and guide you in the right direction.
With the Views shortcode you reference I am unable to perform calculations on the data retrieved. The short code implemented above works for our purposes exactly as needed.
What I now need to know is how I can - either through modification the code above or by any other means - pass a toolset types field as a parameter to my shortcode. I have been researching and it seems I may need to do something small like add:
To restate, my objective is "C" above. Can you help?
C. I would like to be able insert shortcode B as the parameter for shortcode A in the form of this "nested" shortcode:
[taxonomy_term_post_count taxonomy="[types field='fruit'][/types]"]
I need to check on your install what's going wrong there and for that, I need a problem URL where you added the above shortcode as well as access details. Also, an example of your expected output.
*** 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.
My issue is resolved now thanks to the Toolset Facebook User Group:
We used the toolset PHP API. The equivalent of your types shortcode is:
types_render_field( "fruit", array( ) );
So we did something this:
$fruit = types_render_field( "fruit", array( ) );
Then this:
$term = get_term_by( 'slug', $fruit, 'custom-taxonomy-slug');
And added / modified the code accordingly and it worked beautifully without requiring an input parameter since the input parameter is now a part of the shortcode.