Skip Navigation

[Résolu] Custom Shortcode for Term Meta data

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: Custom Shortcode for Term Meta data

Solution: To fetch custom term field values (term meta) inside the post view, you need to add custom shortcode.

You can find the proposed solution, in this case, with the following reply:

Relevant Documentation:

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.

Marqué : ,

This topic contains 4 réponses, has 2 voix.

Last updated by Tom Gonzales Il y a 2 années et 10 mois.

Assigned support staff: Minesh.


Tell us what you are trying to do? I need to pull data from another custom post type (not created with Toolset) and extract a location address from a taxonomy and display it in a View using a custom shortcode.

Is there any documentation that you are following? I found an example in the support forum that I started from and came up with this:

// Term Meta Short Code for Location Address
function display_termmeta_location_address_func($atts)
$slug = get_term_meta( get_the_ID(), 'location_address',true);
return types_render_termmeta( $slug , array() );
add_shortcode( 'display_termmeta_location_address', 'display_termmeta_location_address_func' );

And the shortcode of...

[display_termmeta_location_address slug="location_address"]

Is there a similar example that we can see? Here's a link to the development page with the events data I'm pulling in so far.

hidden link

The plugins taxonomy field I'm trying to display can be found here:

hidden link

The taxonomy meta field I'm trying to display is "location_address"

And my content template looks like this:

<div style="margin-top: 20px;">
Date: [start-new-day]-[end-new-day] [wpv-conditional if="( $(evcal_repeat) eq 'Yes' )"]Recurrence: [wpv-post-field name='evcal_rep_freq'][/wpv-conditional]<br>
[wpv-post-body view_template="None" suppress_filters="true"] [wpv-post-taxonomy type="event_type_4" format="name"], [wpv-post-taxonomy type="event_type_3" format="name"] [start-new-time]-[end-new-time], [wpv-post-field name='evcal_location_name'], [display_termmeta_location_address slug="location_address"], [wpv-post-field name="evcal_cmd_1"] [wpv-post-field name="evcal_lmlink"]

I'm already using several custom shortcodes in this template - [start-new-day], [end-new-day], [start-new-time], [end-new-time] - which are pulled from a custom post field. But I can't seem to figure out how to pull the address from the "location_address" taxonomy term metadata and display it after the location name in the event listing.

Any help would be appreciated.



Languages: Anglais (English )

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

Hello. Thank you for contacting the Toolset support.

Well - first of all, I need some informtaion to understand your problem clearly and I need to know your current setup.

=> What kind of view you are using (Post view or Taxonomy view)?
=> The custom term field is not created with types plugin - correct?
=> Is it possible for you to send me access so I can look at it and fix it for you.

I have set the next reply to private which means only you and I have access to it.



Languages: Anglais (English )

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

Well - within your view's loop output, I've added following shortcode:

Location Address: [show_term_meta]

You can find the code added here:
=> hidden link

function func_get_term_meta_data($atts) {
 global $post;
 $term_ids = wp_get_object_terms( $post->ID, 'event_location', array( "fields" => "ids" ) );
if(is_array($term_ids)) {
 // $locations = get_term_meta($term_ids[0]);
 $locations=evo_get_term_meta('event_location', $term_ids[0]);
  return $locations['location_address'];
add_shortcode( 'show_term_meta', 'func_get_term_meta_data' );

I can see its displaying location address now. Could you please confirm.


Perfect! Plus I learned where to place my custom coding too! I've been placing it in my child theme's funtions.php file.

Thanks for the assistance, Minesh.



My issue is resolved now. Thank you!