Skip Navigation

[Resolved] Display custom fields on the site’s front-end

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 7 years ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Nigel 7 years ago.

Assisted by: Nigel.

Author
Posts
#517743

I am trying to: Display custom fields on the site’s front-end

I visited this URL: https://toolset.com/?page_id=31635

I expected to see: How to do this

Instead, I got: NOTHING!
hidden link

Hi - I just bought toolset (one site for a dry run - I will upgrade when I'm happy with it). I was using the free version but paid money to see how to actually diplay custom fields front-end. I feel like I just slammed into a brick wall - the page I need is missing!!

Please can you help?
Martin

#517752

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Martin

Can I check where you got that link from? Was it a documentation link from within the plugin?

It's clearly broken wherever you got from and if you let me know where I can make sure it is fixed.

In the meantime, I suggest you start with this page: https://toolset.com/documentation/user-guides/view-templates/

If you create a custom post type and add custom fields to it, or if you just add some custom fields to the standard post type, when your theme displays these posts it will likely show the post title and post content, possibly some meta such as the post date and author, but it won't show any of the custom fields.

You can use Views to make a content template where you use Views shortcodes to output the content of the custom fields when the posts are displayed, and that link describes how.

Let me know about the broken link, and feel free to ask any follow-up questions when you've looked at the documentation.

#518164

Hi Nigel

I'm afraid I'm still struggling with the vaery basic issue of how to have a custom field appear front end. Having some spent a fair bit of time on this I'm even now wondering if it's even possible with toolset to add a custom field to a core template.

Here's what I'm trying to do:
hidden link

I created a custom field which now appears in admin on all product pages:
hidden link

How i get this to appear front end is beyond me! (This relates the question above). To add to my frustration, each time you save a custom field you get a little pop up saying 'did you know you can display custom, fileds without a single line of code'. But does it tell you HOW – no sir! Pop up is not live.

I guess this has something to do with Views. I read the instructions but got completely confused by having to create a custom template – I already have a template called single-products.php. I did create a custom template and assigned it to 'products' but that just caused the content field to disappear.

So:

1. Is what I'm trying to do possible?
2. How do you do it?

martin

#518332

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

sample template.png

Hi Martin

I'm sorry if you're getting off on the wrong foot with Toolset.

I see from your screenshots that you are using WooCommerce, and that requires special handling (as described here: https://toolset.com/documentation/user-guides/getting-started-woocommerce-views/).

What I'm not clear about from your question is whether you are directly editing the PHP template files (i.e. you mention single-product.php) or are trying to design the template with Toolset.

So a quick recap.

When viewing single posts on the front end your theme will use the PHP template single.php to render the page (and the actual content part of the page, i.e. the post body, will normally be output using the_content() function). You can add more specific template files to your theme to render posts of a certain type, e.g. single-project.php to render single posts of the custom post type "project".

WooCommerce products are a special case inasmuch the single-product.php is provided by the plugin rather than a theme. I'll come back to WooCommerce in a moment.

Using the Types plugin alone, to render the custom fields added to your posts you can edit the PHP templates and use the types_render_field function as described here: https://toolset.com/documentation/customizing-sites-using-php/functions/

When you add the Views plugin you also have the ability to output these custom fields using shortcodes in the WordPress back-end to save you editing your theme's PHP templates.

How this works is that you create a Content Template (at Toolset > Content Templates) and assign it to single posts of your custom post type, e.g. to single projects. This content template will then take over the rendering of the_content() from the PHP template to output the post body.

In this case you probably don't have a single-project.php (why would you, you are using Views to customise the output) and single.php is being used to render the page. It will call header.php and footer.php (and possibly sidebar.php), it will output the post title and perhaps some post meta such as post author and publication date (depending on your theme), but then Views will intercept the call to the_content() and replace the output with what you design in the content template you assigned.

As the_content() is no longer being used to render the post body, your content template will need to include it itself. (If you use the Fields and Views button to insert the required shortcode it will insert the following: [wpv-post-body view_template="None"].)

In the screenshot "sample template" you can see an example of a template for single projects which outputs the post body, the standard post author field, a logo image and a difficulty level, both from project custom fields created with Types. (I inserted each of these using the Fields and Views button.)

Now when I view a single project post on the front end these fields will be rendered below the post body in the main content area.

Now, WooCommerce requires special handling if you want to use Views to design a custom product template.

If you are editing the single-product.php template then you can go ahead and use types_render_field to output the custom fields.

But what if you want to customise the WooCommerce product template using Views?

Well, you can't (I was careful with the wording of that question). What you can do is replace it with your own custom template designed in Views.

You will need to additionally install the WooCommerce Views plugin add-on and activate it, and visit Toolset > WooCommerce Views.

The "Product Template File" will initially be set to use the default WooCommerce template (i.e. the single-product.php file which ships with WooCommerce). If you want to create a custom design then you need to change this to "WooCommerce Views plugin default single product template". The WC single-product.php template will no longer be used and whatever you add to the Content Template you assign to products will be rendered instead.

When designing the product template you can insert the standard Types and Views shortcodes, as well as special WooCommerce-related shortcodes which you can also insert with the Fields and Views button and which you can see listed here: https://toolset.com/documentation/user-guides/views-shortcodes/. Standard WooCommerce shortcodes will also work.

I hope that is clearer, but if you still have doubts let me know.

I'd encourage you to go through some of our tutorials to get a better handle on using Toolset, such as https://toolset.com/documentation/toolset-training-course/ and https://toolset.com/learn/create-an-ecommerce-wordpress-site/, and Agnes, who creates the tutorials, will be happy to answer any questions about them at https://toolset.com/documentation/toolset-training-course/toolset-training-support-page/

#518352

Hi Nigel

Thank you for that wonderfully comprehensive reply.

I realise that toolset is not for me. Clearly you have to have a pretty hardcore undertanding of WP to use it and a pretty solid knowledge of php. I have neither.

When I made a purchase there was a 30 day refund offered. I went to this link:
https://toolset.com/buy/refunds-policy/ but it's also broken! Can you tell me how to get a refund?

Martin

#518353

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Martin

Actually, you don't need to know any PHP, but you do need a reasonable understanding of WordPress, that's correct.

I'm not sure where you got the link from, it is incorrect.

The correct link is: https://toolset.com/refund-policy/

Thanks for giving Toolset a try.

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.