I have the MetaBox AIO and used it to create a Custom Fields meta box that has a WordPress Post field. Everything is working fine as described in the documentation, but I want to know if there is a way to change the how the data of this field is saved.
This field saves post ID(s) in the database.
If field is not multiple, then a single post ID is saved in the database.
I would like to save the field data as a post_name (slug) instead of ID. This is to make it easier for me when I prepare CSVs to bulk upload posts. For this custom field, I'd rather enter the post_name (slug) in the CSV which is permanent and also clearer than just an ID number. But as things are now, I have to enter it as an ID in order for it to show up correctly.
Can the data of the Post field be saved as a post_name instead of id?
post only supports to save the object ID (post ID) in the database, like the field
taxonomy_advanced. I'm going to create a feature request for the developer team to support saving the slug beside the ID.
These links will help you to do by coding:
Thank you for putting in the feature request.
I didn't understand your suggestion on the
hidden fields. I'm not sure how to apply that. I know how to get the post slug in a WordPress query and how to display it if needed, but that is not what I need now.
What I have are two custom post types (course) and (lesson).
When I create a lesson, a custom field (
post) allows me to pick the course the lesson belongs to.
But because I want to bulk upload hundreds of lessons, I created a CSV file with all my fields including this custom (
post) field. However, I need to fill it in manually by checking the ID of the individual courses.
If I could fill in the slug name it would be easier. That way when I upload these lessons they would automatically be associated with the correct course based on the slug/post name instead of the ID.
This is also useful in the event that I move sites and re-import content without the post IDs, everything will still maintain a relationship based on the post slug/name which won't change and is easier to identify than an ID number.
I hope this clarifies what I'm trying to accomplish.
Please let me know if you have any advice on an existing Meta Box feature that can help accomplish this until the
post field can support saving the slug in the database.
Alhamdulillah, I found a working solution to my issue that involved creating a custom taxonomy for my lesson post type which is auto-populated with terms based on the course post type title and slug.
I worked with MetaBox custom fields plus the second part of this tutorial here. It works perfectly, in case anyone else needs the same solution.
So now I can use the post slug in the database files to maintain the relationship between lessons and courses (and to easily bulk upload what I need). Meta Box handles my custom taxonomy, but the code snippet I linked to deals with the auto-population of the terms.
The nice thing is with Meta Box handling the custom taxonomy and meta boxes I easily get the filter and quick edit features set up. It took so little time and effort. This plugin is really worth the cost.
In conclusion, issue resolved with a workaround. 🙂