Error saving content settings: Invalid page template

I have a client site running the newest versions of X Theme and Cornerstone.

When trying to save in Cornerstone for custom post type, I get the error:

“Error saving content settings: Invalid page template”

Here is what causes it:

  1. I’m using a custom post type, Recipes.
  2. I set the page template to full-width. I suspect it would work with any template though.
  3. I click save.

In the console in Chrome, I see the error: “Error saving content settings: Invalid page template”

Is that something familiar to you? Is there a way to avoid this?

It might help to know what other plugins we’re using. I was hoping you’d look in to it though since it happened in Cornerstone. I’m sure it’s easy to blame the other plugins but I know those developers aren’t going to help me since they are free plugins, and they aren’t going to attempt troubleshooting Cornerstone.

For the recipes, we are using:
WP Ultimate Recipe v3.7.0

And to select a custom template, we are using:
Custom Post Type Page Template v1.0.1

We needed the second plugin because WP Ultimate Recipe seems to really hijack the native WP template-choosing functionality.

Any idea what might be causing this?

Hi There,

We can check the issue but if the conflict is coming from a third party plugin we can’t promise a fixed. Can you try first using the No Container | Header, Footer template. Without the container, your content will be fullwidth too edge to edge of the browser. If the issue persists after this, please share site URL and credentials on a secure note.

Hi Lely,

I tried the No Container | Header, Footer and it also did not work.

To test the problem, go to Recipes -> Test Recipe

It’s a draft, but you can go ahead and try to use cornerstone and save and you’ll see it isn’t working. Check the console and you’ll get the specific error.

Hi Brian,

First of all, you added the User/Pass of your website publicly which is wrong. I edited your post and put the information to the Secure Note, but I strongly suggest that you change the password of your website ASAP. You can use the Secure Note functionality of the post to add private information which will be available only for us.

Now regarding the case, to show you that the Cornerstone can be used on Custom Post Types I installed the Custom Post Type UI plugin on your WordPress installation and created a new custom post type called xtest.

Then I used Cornerstone to add a new page and here is the result:

As you can see it is working ok and I added an Alert Box there using the Cornerstone. The problem is indeed the WP Ultimate Recipe plugin which you need to contact them and ask for details.

Thank you for your understanding.

1 Like

Hi Christopher,

I spent a long time trying to figure out how to make my post secured and could not find a single option to do so. I’m looking now and I see there isn’t one. None of the buttons in the top of this edit screen make any part secure, and there are no additional options. As far as I can tell, the only way to add secure info is to post, and then click “Secure Note” afterwards? If so, that’s very, very difficult for people to figure out. I saw “Secure Note” on my first post and it looked like a label , so I assumed that the whole thread was secure, hence why I shared the credentials.

I don’t know if this is your own forum software or not, but I would change that right away because it’s extremely confusing for users.

Anyway, thank you for looking in to this for me. I’ll keep investigating and let you know if I have any other questions.

The developers of WP Ultimate Recipe are saying that the error has nothing to do with them. Obviously it is related to their post type specifically but it doesn’t mean the problem is theirs. Mostly I just want to find a solution!

I narrowed down the error message to Cornerstone specifically.

I found that it is generated by cornerstone\includes\classes\content\class-content.php, lines 111-113, which are:

if ( is_wp_error( $settings ) ) { throw new Exception( 'Error saving content settings: ' . $settings->get_error_message() ); }

An error was triggered somewhere, presumably during the save process. The function (is_wp_error) is a core WP function. Digging deeper, I found the specific WordPress core file responsible for generating the error “Invalid Page Template”. The file is wp-includes\post.php, and lines 3411-3422 are responsible, which are:

if ( ! empty( $postarr['page_template'] ) ) {
	$post->page_template = $postarr['page_template'];
	$page_templates = wp_get_theme()->get_page_templates( $post );
	if ( 'default' != $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) {
		if ( $wp_error ) {
			return new WP_Error( 'invalid_page_template', __( 'Invalid page template.' ) );
		}
		update_post_meta( $post_ID, '_wp_page_template', 'default' );
	} else {
		update_post_meta( $post_ID, '_wp_page_template', $postarr['page_template'] );
	}
}

Nothing jumped out at me from that, so I couldn’t tell why the error is coming. I do know that even for these recipe posts, they save just fine and without error if I’m just using the default WP editor. Even with the page template selected.

If I try to use Cornerstone, it breaks.

Digging in to the database, I found that these posts have a row in wp_postmeta whose meta_key is “_wp_page_template” and the value, in this instance, is “template-layout-full-width.php”.

Those values are all correct, so why would it be reporting an error?

Is there some way we could narrow this down or dig deeper to figure out what’s happening?

The issue comes from Custom Post Type Page Template plugin. It is not compatible with Cornerstone. To make it work, you should choose the default template, edit your (custom post type) page in Cornerstone, save and switch back to other page templates.

You could try the new WordPress supported method in integrating page templates to custom post types. See https://codex.wordpress.org/Post_Type_Templates. Please note though that this requires custom development so this would be outside the scope of our support.

We do have an in-house custom development team that offer paid services, who may be able to assist. They can be contacted at pinnacle@theme.co if this is of interest to you.

Thanks.

Thank you for your response.

Your solution is actually what I had already been pursuing as a workaround. I had one heck of a time getting the template file to work, though. Unfortunately you can’t just copy the “full width” page template file into “single-recipes.php” in your child theme and have it work. I had to do a ton of troubleshooting and ended up having to hard-code classes into some divs, most notable the “main” div, otherwise the incorrect classes would be generated and the page wouldn’t be full-width. Kind of annoying.

Is there any better documentation on using custom template files within Cornerstone? Hard-coding classes seems like kind of a hack that will break in future X Theme versions.

Hi There,

You are always welcome!

See this: https://theme.co/apex/forum/t/customizations-best-practices/205
On the root folder of the theme, we can see the following template files:

Each of those templates files are calling certain template parts on each of the stack folder here:wp-content\themes\x\framework\views. Since we cannot control how a third party plugin works, what you did adding those classes is the best workaround for now.

Hope this helps.

@christopher.amirian I’m a newbie to custom post types but I’m determined to learn how to do this with X. I’m 99% there, I think. Could you please help me with this? Thank you in advance for any insight you can give me!

I have created a custom post type with Custom Post Types UI plugin and custom fields for it with ACF. I went to Cornerstone settings in the Dashboard and selected my custom post type, and I can now edit it in Cornerstone. I know how to create a new template from within Cornerstone.

But when I go to preview the page, all I see is the post title, my username, and the date.

Here are my questions:

  1. How do I get the information I type in my custom fields for this custom post type to show up in Cornerstone?
  2. There’s no template to choose from when I look at the custom post type post in the regular editor view.
  3. How do I make it so my name and the date don’t show up a the top of this post?

Hi there,

  1. You mean the custom fields created through ACF? You’ll have to use their provided shortcode and add it to cornerstone text element. https://www.advancedcustomfields.com/resources/shortcode/

Example, [acf field="first_name"]

  1. Page templates are only applicable for page types, which is why we don’t recommend plugins that forcing the post types to use page templates, page types have features that may not be available for custom post types. Plus, your created custom post type inherited the post instead of the page.

  2. As it inherited the post type, it will display the post meta as well. Do wish to disable it globally or just hide it on your specific custom post type?

a. Disable it globally, please go to Admin > X > Launch > Options > Blog > CONTENT > Post Meta and turn it off.
b. Or to hide it to specific custom post type, then please add this code to your child theme’s functions.php

  function x_does_not_need_entry_meta() {

    $post_type           = get_post_type();
    $page_condition      = $post_type == 'page';
    $post_condition      = $post_type == 'post' && x_get_option( 'x_blog_enable_post_meta' ) == '';
    $portfolio_condition = $post_type == 'x-portfolio' && x_get_option( 'x_portfolio_enable_post_meta' ) == '';
   
    if ( $post_type == 'your_post_type' )  return true;


    if ( $page_condition || $post_condition || $portfolio_condition ) {
      return true;
    } else {
      return false;
    }

  }

Then just change the your_post_type the name of the post type you created.

Thanks!

1 Like

Thanks, Rad. I did turn the meta off in the Launch Options. I think the plugin must have added it back in… Anyhow, I think I’m going to switch tactics with the custom post types. Thanks.

Hi there,

Kindly open up new threads for additional questions as it will help us to focus on each issue and give you a better support which you deserve. Having a long threads makes the maintaining job harder and also it will be harder for the other customers to find the correct information if they have similar issues. You are always welcomed to reply to this thread to follow up the same question.

Also, regarding the Custom Post Type, I suggest that you use the Code Generators rather than plugins. You can simply add the code to the functions.php file of your Child Theme and have the desired Custom Post Type.

Kindly check this: https://generatewp.com/post-type/

For further questions kindly open up a separate thread.

Thank you.