Skip Navigation

[Fermé] Using types for custom shortcodes?

This support ticket is created Il y a 8 années et 8 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 réponse, has 2 voix.

Last updated by Waqas Il y a 8 années et 8 mois.

Assisted by: Waqas.

Auteur
Publications
#293165

Sorry, I originally typed my request into the debug box.

I am trying to figure out a solution for creating custom shortcodes using types and views. I have a type of Site Variables with some custom fields on it. What I want to do is pull these custom fields into my content templates. There will only be one post in the Site Variables types which will contain all of my site variables. Currently when I insert with a shortcode into the content template for a site variable custom field there is nothing being shown.

#293340

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

You can use [wpv-post-field] short code in your View or Content Template to retrieve the custom fields, within the current post loop or from another post, like:

[wpv-post-field name=??my-custom-field?? id="99"]

where:

- "name" parameter defines the slug of your custom field (complete slug)
- "id" parameter defines the ID of the target post (whose custom field you want to grab)

Please see https://toolset.com/documentation/views-shortcodes/#wpv-post-field for more information.

On the other hand you can create custom short codes using Word Press API's add_shortcode() function. Please see http://codex.wordpress.org/Function_Reference/add_shortcode for more information.

You can create a short code to receive the same parameters as of [wpv-post-field] and can grab the required content. Following code does the same, you should add this in your theme's functions.php file:

function grab_custom_field($atts) {
     $name = $atts["name"];
     $id = $atts["id"];

     return get_post_meta($id, $name, true);
}
add_shortcode("get-custom-field", "grab_custom_field");

And use the short code as below (wherever you want):

[get-custom-field name=??my-custom-field?? id="99"]

Please see http://codex.wordpress.org/Function_Reference/get_post_meta for more information about get_post_meta().

Le sujet ‘[Fermé] Using types for custom shortcodes?’ est fermé à de nouvelles réponses.