In your 2nd code snippet, you’re redefining $post_args
for each $movie
. Try this instead:
$post_args = array();
foreach($movies as $movie) {
$i++;
$post_args[] = array(
array(
'key' => 'title' . $i,
'value' => $movie['title']
),
array(
'key' => 'qty' . $i,
'value' => $movie['qty']
),
array(
'key' => 'desc' . $i,
'value' => $movie['desc']
)
);
}
wp_insert_post( array(
'post_title' => '1',
'post_type' => 'departure',
'meta_input' => $post_args
) );
Related Posts:
- How do I pass an array as an argument to a WP-CLI command?
- Update post meta does not serialize array
- Print specific values stored in a post meta array
- wp_insert_post($post), add an array of values with update_post_meta
- Nice way to print_r arrays
- Why does get_users suddenly return duplicates?
- WordPress: How to use post_class() in an echo
- Building a scalable WordPress favouriting plugin – one serialised meta value array or many meta records
- Passing a variable into Contact Form 7 [closed]
- update_post_meta from data in multidimensional array created from a form
- settings api store multiple array
- if is_singular array not working as expected
- Add a default meta_value to new posts
- Get posts id in array by meta value and key
- How to save array of datas in option page by setting api?
- Sort a custom post type array numerically
- How to add day number and initial to my post graph?
- How to validate register settings array
- How to check an array of $curauth fields?
- Problem with wp_update_post
- Replace text inside a huge multidimensional array
- update_post_meta() with a modified array?
- How to get update_post_meta output to include string length
- How pass a 0 in $atts?
- Retrieving multiple values to the Post Meta (using an array)
- Echoing a variable inside a function
- How to Translate a string of an array inside a class?
- Combine get_page_by_title to exclude pages from wp_list_pages
- Plugin settings page checkbox not saving – one options array with sub array
- Struggling with array and foreach loop
- Customizer Settings in Arrays
- Custom order for Mysql array
- WordPress i18n in Array throws Error
- How to decipher the following array
- Save meta box values as an array to wp_postmeta
- How to display line breaked meta values in table?
- Grouping posts by a custom meta value
- Organizing and grouping an array by year
- Array in meta key?
- Does meta_value (array) work with ‘orderby’?
- How to use array in function to get only value I want
- Obtaining values from objects
- How to get a page array and category array going at the same time?
- get_the_terms, whether I should use string or array as the second parameter?
- How to order users by a date in the meta_value array
- Obtaining array item from WordPress revisions output
- Matching slug terms from one array to those in array of WP_Term objects to output term names
- Do not replicate items if they exists in a foreach loop
- WP Page Options Array
- Array is not working in Filter?
- How to put an array in wp user query
- Get the values from an array string to work with post__in
- Inserting a random number into an array [closed]
- Random element in get_post_meta array
- update_user_meta duplicates entry
- Add formatting to Array
- Show array of meta_value in Edit Post Coloum
- How to randomise my menu items?
- How to get the `comment_post_ID`?
- Retrieve array items without page ID
- How do i fix this “call_user_func_array()” error
- How can I get the content of the current page in my loop while merging post-type
- update_post_meta adding to array instead of replacing value
- WordPress meta query with meta serialized data array value
- Add Array record to Meta Post
- Reading Content in an Array as it relates to a meta_query
- How to output get_tags array list to select box
- How to avoid duplicate users when I am using get_users?
- How to add each letter, entity, special character from post title to array
- Multiple meta key and value search in the query
- Strange Behavior with update_option
- wp_update_post to set post IDs to drafts not working
- How i can extract data
- Show Tags of Custom Post Type outside of Loop
- “Undefined variable: array” Error In Displaying Post Tag
- How do I pull post from standard post format?
- WPML admin texts with serialized objects
- How to display checkbox meta array values one by one?
- Plugin Shortcode value in post
- how to query for meta_value have array
- Create dropdown menu of all tags used in category
- Use $wp_customize->add_control to create a selectable “Designed/Powered By” choices select w/ link in footer?
- Echo the key from a select-box in Array with get_option (Settings API)
- Updating wordpress user meta data array (unexpected multiple arrays)
- update_post_meta array issues
- Update Post Meta for Arrays — Remove/Replace Single Value from Multi Dimensional Array
- Get custom_user meta value and add entry
- How do I retrieve a value from a multi – dimensional array using get_post_meta? [duplicate]
- How do I retrieve an array from wp_postmeta with get_post_meta?
- post custom values
- Accessing array elements (get_pages)
- Printing out JSON array returned [closed]
- How to check if the postID is in an array? [closed]
- Fatal error in my WP
- Marketpress php warning on server, no problem on localhost [closed]
- SQL query add only posts with custom field to array
- Combine two foreach Arrays into one table row
- How to match data in multidimensional array of post_meta_data?
- how to separate array with commas? [closed]
- JSON webhook WP Automator – Help with Syntax [closed]