Skip Navigation

[Resolved] I can't set a default Content Template on a custom post type

This support ticket is created 3 years, 12 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 15 replies, has 2 voices.

Last updated by stefanoC-6 3 years, 11 months ago.

Assisted by: Waqar.

Author
Posts
#1949857

Tell us what you are trying to do?
I can't set a default Content Template on a custom post type
Is there any documentation that you are following?
No
Is there a similar example that we can see?
hidden link
What is the link to your site?
hidden link

When I create a post on wordpress from the back o frontend I can't see the content if II don't select the content template from the Gutenmberg Editor.

#1950975

Hi,

Thank you for contacting us and I'd be happy to assist.

Can you please go to WP Admin -> Toolset -> Content Templates and see if any content template has been assigned to this custom post type?

If not, you can use the change usage link to assign it, from the action bar that shows when you'll hover over the template's title.
( screenshot: hidden link )

In case the issue still persists, you're welcome to share temporary admin login details in reply to this message.

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

#1951793

Thank you for sharing the admin access.

I've noticed that WordPress and a number of plugins including the Toolset ones are not updated to their latest versions.

To troubleshoot this, I'll suggest the following steps:

1. Please make sure that WordPress, active theme, and plugins are all updated to the latest versions.

2. It would be interesting to test this with all non-Toolset plugins disabled and a default theme like Twenty Twenty-One.

If it's fixed, you can start adding the disabled items, one-by-one, to narrow down to a possible conflicting one.

3. In case the issue still persists, I'll need your permission to download a clone/snapshot of the website, to investigate this on a different server. This way your actual website won't be affected.
( ref: https://toolset.com/faq/provide-supporters-copy-site/ )

Please let me know how it goes.

#1952107
Schermata 2021-02-16 alle 17.01.22.jpg

I don't see the content with another theme

#1953463

I'm trying to add this javascript code on the post form to add the shortcode:

<script type="text/javascript">
document.getElementById("cred_form_97499_1-submit-1-1613548904").addEventListener('click', function () {
var text = document.getElementById('[wpv-post-body view_template="journalist-identikit"]');
text.value += ' after clicking';
});
</script>

but I don't see the results on frontend

#1954053

Thanks for writing back.

I see that the Toolset plugins are updated to the latest versions, but WordPress is still an older version. I'll recommend updating it to the latest version too.

I've checked a couple of "Journalist" posts and the content template "Journalist Identikit" seems to be showing correctly.

I'm also not sure exactly what you expected from the custom script, since shortcodes can't be inserted through the scripts. If you could share more details about this requirement, I'll be in a better position to suggest a better approach.

#1954059

My problem is on creation of the Journalists single posts. I'm using the cred post from the frontend and this kind of creation post doesn't consent me to set the journalist content template. I'm looking for some workaround to insert the shortcode automatically because Toolset don't set this kind of content template for any journlist-posts.

#1957897

Anybody can help me on this topic?

#1957947

Thank you for waiting and I apologize for the delay in getting back on this.

I've performed some tests on my website with a new post form and the assigned content template is automatically applied to the new posts created using the front-end form. No extra workaround or script is needed for that.

Next, I removed the following script from your website's form "Add Journalist", and used it from the page "The Journalists", to submit a test entry "Test entry from TS support":


<script type="text/javascript">
document.getElementById("cred_form_97499_1-submit-1-1613548904").addEventListener('click', function () {
    var text = document.getElementById('[wpv-post-body view_template="journalist-identikit"]');
    text.value += ' after clicking';
});
</script>

If you'll check that new post in the admin area, you'll see that the designated template "Journalist Identikit" is automatically assigned to it, as expected.

Please feel free to test the form again and in case the issue still persists, please share the exact steps.

#1957955
Schermata 2021-02-19 alle 09.31.12.jpg
Schermata 2021-02-19 alle 09.29.57.jpg
Schermata 2021-02-19 alle 09.29.50.jpg

What you have tested is ok, but there is not any result on the frontend and I need to put manually the custom template content shortcode to see the results. I see the grey background when I aspect to see the custom fields.

#1958125

Thank you for sharing these further details and I now understand what you mean.

A quick fix would be to use the "cred_save_data" hook to make the form, automatically insert the content template shortcode in the newly created post.
( ref: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data )

For example:


add_action('cred_save_data','func_custom_post_content',10,2);
function func_custom_post_content($post_id,$form_data) {
	if ($form_data['id']==97496) {
		$args = array('ID' => $post_id, 'post_content' => '[wpv-post-body view_template="journalist-identikit"]');
		wp_update_post($args);
	}
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

To properly investigate why you're facing this issue in the first place, I'll need your permission to download a clone/snapshot of your website, to run some tests.
( ref: https://toolset.com/faq/provide-supporters-copy-site/ )

#1958223

Don't work:

hidden link

The content is empty.

#1958247

It is strange that this code worked on my test website, but not on yours.

Do I have your permission to download a clone/snapshot of your website?

#1958361

You can do all the tests you need.

#1958469

The ID of the post cred was wrong. Now I've updated with the right ID and it's ok, thank you so much for your assistance.