How to set Title on CPT from custom field value instead of Auto-Draft defaults

Support General How to set Title on CPT from custom field value instead of Auto-Draft defaults

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #40258
    Dustin DaunceyDustin Dauncey
    Participant

    Hello,

    I disabled Title support in the CPT via Metabox as I want to use only the custom fields I've created. I noticed that the URLs used on these entries though always have "auto-draft" in the URL I presume since there's no Title officially set. How can I get the title to be set on save (or edit the permaslug for it) to match the value of one of the fields called "name" for example?

    I found this but I'm still struggling to follow this: https://support.metabox.io/topic/adding-metabox-field-data-to-the-post-title/?swcfpc=1#post-24634

    Wanted to see if there was a different method or perhaps a more descriptive example by any chance.

    #40265
    PeterPeter
    Moderator

    Hello Dustin,

    I think you should keep supporting the Title of the CPT. Then use the code to update the whole post title by the field value after saving the post.

    #40301
    Dustin DaunceyDustin Dauncey
    Participant

    I'm a bit confused by this. How does someone normally go about creating a completely custom post-type which doesn't support the Title attribute and set the permalink with the value of a particular attribute? The code option seems very cumbersome. Why this isn't exposed in the GUI is strange to me.

    Or is it more recommended to use the Title option to essentially replace the "Course name" custom field for example so that it removes this issue? In that case is it recommended to still use "Course name" and have it match the Title attribute so it's essentially a duplicate, or is it better to just not have a "Course name" field since the Title field is then exposed instead?

    #40331
    PeterPeter
    Moderator

    Hello,

    The pretty permalink (post name) is generated from the post title so if you do not have the post title, it might not work properly. You can read more here https://wordpress.stackexchange.com/questions/43102/permalink-not-working-for-page-without-title

    It's the standard feature of WordPress so I highly recommend using the standard post title when registering the CPT. You can use the custom field value to replace the post title after saving the post.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.