Answer the question
In order to leave comments, you need to log in
How can I add an object field to a post in Wordpress?
The essence of the question is that there is a post type "Match" and inside this type of post I need to have such a repeatable field as "Goals" and in this field I need to store values like: "Player ID: Number of goals".
The question is, how is it possible to store the values of such a field within a given post type? Is it possible to save objects inside a post? Or, in this case, will it be necessary to create another type of post (goal) and link it to the match?
Answer the question
In order to leave comments, you need to log in
Fields are used to store record data post_meta
. It is most reasonable to store a string or an array in this field, but you can experiment with objects too
$competition['Барселона'][] = [
'time' => '27:01',
'person' => 'Месси',
];
$competition['ПСЖ'][] = [
'time' => '32:16',
'person' => 'Мбаппе',
];
$competition['ПСЖ'][] = [
'time' => '70:44',
'person' => 'Кин',
];
update_post_meta( $post_id, '_competition', $competition );
get_post_meta()
$competition = get_post_meta( $post_id, '_competition', true );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question