E
E
eugene1122018-04-30 22:05:03
WordPress
eugene112, 2018-04-30 22:05:03

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:
5ae7671e31def553898856.png
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.
5ae7683d58e87954313122.png
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

2 answer(s)
I
Igor Vorotnev, 2018-05-01
@eugene112

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 );

https://wp-kama.ru/hook/wp_insert_post_data

N
Nikolai Mironov, 2018-05-16
@solidcreature

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 question

Ask a Question

731 491 924 answers to any question