I am trying to display custom fields using VIews after creating a new content type ("pledge").
I've been able to customise the view for the pledges "archive" and create a view used as a "widget" to display the last created pledges.
My problem is with the display of custom fields in a single instance of "pledge". Only the 'post' part is being displayed.
've followed the procedure in the documentation which is to create a a "Content Template". It looks like it is never called.
<?php echo "Hello World"; ?>
[wpv-post-title]
[wpv-post-field name="impact"]<br/>
[wpv-post-field name="location"]<br/>
[wpv-post-field name="email"]<br/>
I've tried all the options "Use this Content Template for:" single pages or post archives, still nothing... I've tried to set the templates in the "Custome Fields" to no effect either...
This shouldn't be too complicated to fix, but I'm stuck.
Hi,
to display the custom post fields of a custom type you can:
- use the 'type' short-code, it should look something like:
[type field="impact"][/type]
- use 'wpv-post-field', to show the raw data from the field:
https://toolset.com/documentation/views-shortcodes/#wpv-post-field
The custom post fields name are saved with a prefix: "wpcf-" in the database.
To add the 'type' short-code you can use the "Views" button just above the 'content area' in the Content Template you defined, the custom post fields are under the "Details" section ("Details" is the name of the custom field group you declared)
In this link is shown How-to-Edit Content Template:
https://toolset.com/documentation/user-guides/editing-view-templates/
If the above solution didn't work, you may need to check if the content template is working with your theme. To know more about it, please, visit:
Views >> Settings >> Theme support for Content Templates.
Let me know any questions you have about this.
Thank you Selenas for your detailed feedback.
I'm using "Active" as a theme. I have been looking in the PHP files:
* blog.php: Blog (full posts) Page Template uses" the_content" once
* content-right-page.php also
* ... and a few others
<?php the_content( __( 'Read more ›', 'responsive' ) ); ?>
The debugger works everywhere, but on the full posts / pledges (the extension of posts I've defined).
What should I try next???...
Well, Selenas, problem solved!
When I edit a "pledge" (extended type) I have the option to set its template. It works!
So the trick was (after too many hours) to set the template after editing the instances of the extended type that was created before.... their extension...
So, there was one step missing (for the casual user of WP) to connect a new type to a template: As the extended type is created before its template, it is necessary to go back to the extended type to set the right template (this is explained in the doc, but not elicited enough probably — a small schema might help). Setting the link to the template in the extended type will only work with the instances created after everything is in place. For the existing instances that have been "extended", it is done through editing the instance directly.
Sounds logic 🙂
Have a great day, and thanks again for your help.
Serge
Hi,
Thanks for sharing your solution, it may help other clients.
Just for your information, this issue can be fixed in two way:
- the first one is the solution you provided. Reassign the Content Template to the custom post type/post/page. Or,
- you can do it by using the "Apply to All" in the Content Template editor. See step 5 here:
https://toolset.com/documentation/user-guides/view-templates/