Answer the question
In order to leave comments, you need to log in
How to change the key field when viewing posts in the admin panel?
Hello everyone, I'm starting to get acquainted with the VP, I don't even know how to ask the right question.
Basically, I need to be able to add new elements to the slider with an assortment of colors, using the Advanced Custom Fields plugin, I made a form of this type:
In my post type, I removed the title and editor, adding my fields there.
As a result, when I save a post, it is signed "Draft" in the general list.
PS The bottom two posts were made before the title was removed from the custom post type.
Is it possible to make my custom field (for example "Rose Size") the key field (instead of the Title), or is it better to return the title back, thereby replacing it with mine?
Apologies if this has already been asked, and thanks in advance to everyone for their replies.
Answer the question
In order to leave comments, you need to log in
When you turn off the Title on a Custom Post Type, it still remains in the wp_posts table, and is actually needed. Only its UI in the admin panel is disabled. So that the field in the database is not empty, WP generates a default value for it. You can instead install your own, whatever you like:
function my_custom_title( $data, $postarr )
{
if( $data['post_type'] === 'my-post-type' ) {
// вот тут присваиваете нужное вам значение
// посмотрите что в массиве $postarr, там должно быть ваше кастомное поле
$data['post_title'] = 'my post title';
}
return $data;
}
add_filter( 'wp_insert_post_data', 'my_custom_title', 10, 2 );
Eugene (I hope I guessed it by his nickname), you are moving in the right direction, ACF is a great plugin for creating custom sliders. To make it even more convenient, purchase the PRO version, it costs $25, and fantastic prospects will open up.
First, instead of individual records, you can use the Repeater field (repeater), in which you can specify any set of fields. The issue of editing on pages with a list of posts will disappear automatically
Here is an example of a slider (on each slide there is a photo, city, quote, quote width and location):
This is what it looks like with ACF PRO
Secondly, this is not the only advantage of the pro version
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question