Sauter la navigation

[Résolu] CPT without title

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
Hi, I have created a CPT "Inquiry" without title
This CPT is related to the CPT "Customers".
If I add an "inquiry" to a "customer", Toolset request anyway a title

Solution:
This can't be done, currently. It will need custom code. Check this reply https://toolset.com/forums/topic/cpt-without-title/#post-1844291

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

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: Africa/Casablanca (GMT+01:00)

Ce sujet contient 3 réponses, a 2 voix.

Dernière mise à jour par Puntorosso Il y a 4 années et 5 mois.

Assisté par: Jamal.

Auteur
Publications
#1842917

Hi, I have created a CPT "Inquiry" without title

lien caché

This CPT is related to the CPT "Customers".

If I add an "inquiry" to a "customer", Toolset request anyway a title.

lien caché

How can I avoid that?

Thanks. Best

#1844291

Hello and thank you for contacting the Toolset support.

Toolset requires a title for a related post that is created from the backend. The title is used to generate the slug of the new post and is also used in the table of the related posts. Check this screenshot lien caché

I am not sure what is the real reason behind, so I'll need to check this with our 2nd Tier or our developers.

In the meantime, I run a test on a clean install and I came up with a hacky workaround. It consists of a custom Javascript code that does two things:
- Modify the AJAX request that will create the post to make sure it has a (default)title.
- Hide the title input in the "Add new Inquiry" modal window.

I added the custom code to a Javascript in the theme. Then I enqueued it using a PHP snippet. I used the Snippets plugin for that reason. You can check my example on this test site lien caché
Please note that the test site will be available for 7 days.
You can try to add an Inquiry to this customer lien caché

Check this screencast lien caché

Please note that you will have to hit "Enter" as it won't be enabled because the title is empty.

The Javascript code is as follow, and I put it inside a "my_customer_admin_script.js" file inside the theme folder:

jQuery(function($){
	$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
		if ( originalOptions.data['wpcf[post][post-title]'] == "")
			options.data = $.param( $.extend(originalOptions.data, { 'wpcf[post][post-title]' : "Some Default Title"}) );
	});
    $('body').append('<style>input[name="wpcf[post][post-title]"] { display:none; } label[for="types-new-post-type-title"] { display:none; }</style>');
});

The PHP code to enqueue the file for only the custom edit screen, you can edit it here lien caché:

function wpc_add_admin_cpt_script( $hook ) {  
  
    global $post;  
  
    if ( $hook == 'post-new.php' || $hook == 'post.php' ) {  
        if ( 'customer' === $post->post_type ) {       
            wp_enqueue_script(  'myscript', get_stylesheet_directory_uri().'/my_customer_admin_script.js' );  
			// wp_add_inline_script('shapeSpace_script', 'console.log("Bingo")', 'before');
        }  
    }  
}  
add_action( 'admin_enqueue_scripts', 'wpc_add_admin_cpt_script', 10, 1 ); 
#1846381

Our developers have an of feature to implement that will allow more control on the fields to use on the related posts popup. We have added this use case(CPT not supporting title) to the list.

We can't really tell when this will be implemented. Please let us know if the suggested workaround is a viable solution for you.

#1857755

Hi,

sorry for the delay.
Your solution works great, thanks for it.

It is possible to get the parent post title to use as "Some Default Title" in the javascript code?

Thanks
Best