It’s unclear to me why a single event would need more than one row per event. Even if it were a tournament, each game would be a separate event with its own time, place, etc. Multiple events could be tied together when necessary with taxonomy terms.
In any case, you can store arrays of data in meta data, or even in some arbitrary format such as CSV or JSON, so storing multiple rows isn’t an issue. What would be an issues querying for such data. Say you want to query for events in a certain date range. This can be done easily for dates the post was published, but to query for dates in meta data that were saved as an array is problematic.
You’ll at least need to store some data under its own meta key so it is more easily queried. It’s still possible to store multiple values of one event in one column under a single meta key. But if there will be frequent queries utilizing a number of meta data fields, you may want to consider storing the data in a custom table. Complex meta data queries are not very efficient.
@bcworkz thank you for your answer.
For example, the event could be “National fencing tournament 2020”.
This event will take place from the 2 March to the 15 March 2020, the rows of this event are:
2/3/2020 | Male sword |…
3/3/2020 | Female sword | …
4/3/2020 | Female saber |…
Each of them isn’t an event, you can call it subevent, but almost all the properties of these subevents are shared with each other.
Yes, I could use a JSON in a meta-tag to store the data, it is a good idea.
It will be easy to retrieve this data with the related event and show them with the REST API.
The problem now is how to let the operator add this data from the back-end (WordPress).
Which direction should I take to modify the content-type?
cld
You can add a custom meta box to the existing edit screen. Depending on what’s already there and what hooks might be available, you could potentially add input fields to an existing meta box. Alternately, use one of the custom fields plugins to add input fields.
You would then add a callback function to one of the save post or post transition actions to collect the field data and aggregate it into an array or JSON, which is then saved under an appropriate meta key. PHP arrays get serialized when saved to post meta, which is somewhat similar to JSON. Unless the code utilizing this data needs JSON, it’s typically easier to just save the PHP array.