Skip Navigation

[Resolved] Nesting a Toolset Types Field in a Custom Shortcode

This support ticket is created 4 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by andrewF-6 4 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#1534547

Tell us what you are trying to do?

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 ) {

$atts = shortcode_atts( array(
'taxonomy' => null
), $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!!!

Is there any documentation that you are following?
https://toolset.com/documentation/user-guides/views/shortcodes-within-shortcodes/

#1535105

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I'm not sure why you created the custom shortcode that returns the post count for the taxonomy term.

Views offer the shortcode that displays the taxonomy post count which you can use within the taxonomy view:
=> https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-taxonomy-post-count

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.

#1535119

Dear Minesh,

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:

 extract(shortcode_atts(array(
        'YOUR PARAMETER' => 'YOUR PARAMETER'
    ), $atts));

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]"]

Thanks

#1535173

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

How you are passing the shortcode looks OK to me:

[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.

#1535345

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.