To start, why do you want to have your tag data in tags and also in a custom field? Seems to me like there is no reason for this, but maybe I’m missing something.
To answer your question about the code you have.. inside your foreach you overwrite the value each time in the loop. Instead of overwriting, you should add new tags to your predefined variable. Try this:
$all_post_tags = get_the_tags();
$count = 0;
$comma_sep = ', ';
if ( $all_post_tags && !empty($all_post_tags) ) {
$get_all_tags="";
foreach ( $all_post_tags as $tag ) {
$get_all_tags .= $tag->name . $comma_sep;
}
add_post_meta($post->ID, 'all_tags', $get_all_tags, true);
}
Related Posts:
- Can I exclude a post by meta key using pre_get_posts function?
- Custom post meta field effect on the performance on the post
- How to get custom post meta using REST API
- Difference between meta keys with _ and without _ [duplicate]
- Orderby meta_value only returns posts that have existing meta_key
- What is the index [0] for on post meta fields?
- What is “meta_input” parameter in wp_insert_post() used for?
- How to enable revisions for post meta data?
- The “_encloseme” Meta-Key Conundrum
- Best way to programmatically remove a category/term from a post
- Using get_post_meta with new_to_publish
- Custom field metabox not showing in back-end
- So much data in postmeta
- Can I count the number of users matching a value in a multiple value key?
- When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
- How to hide meta box values from custom fields list?
- Auto sort the wp-admin post list by a meta key
- get_post_meta() unserialize issue – returns boolean(false)
- What is the advantage of the wp_options design pattern?
- Storing meta fields multiple times OR once with multi dimensional array?
- Allow user to create instances of custom field
- display specific custom fields
- Is there a hook / action that is triggered when adding or removing a post thumbnail?
- Meta keywords and descriptions plugin for manually editing meta for each page/post
- passing argument to get_template_part() or a better way to code
- Is it possible to store arrays in a custom field?
- Get updated meta data after save_post hook
- Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
- Save HTML formatted data to post meta using add_post_meta()
- importing data from non-wordpress mysql db
- How to convert custom field value to tag
- Create meta boxes that don’t show in custom fields
- Transients vs CRON +Custom Fields: Caching Data Per Post
- Plugin to auto convert custom fields to tag
- Unable to save datetime custom meta field using update_post_meta() function
- Up/Down voting system for WordPress
- post meta data clearing on autosave
- Create custom field on post draft or publish?
- Display info from custom fields in all images’ HTML
- Ordering posts by anniversary using only day and month
- get_post_meta fields don’t show up on posts page
- Update meta values with AJAX
- How to break meta values into different items and avoid duplicates?
- copy attachments to another post type and change attachment url
- Cannot edit post meta fields with rest API
- ajax delete value from custom field array
- Save attachment custom fields on front end
- How to use pagination with get_post_meta
- Copying Custom Meta Values from existing post to a duplicate post
- Add a post meta key and value only if it does not exist on the post
- Move value of one custom field to another
- Order posts according to user defined order for meta values?
- Displaying posts with only upcoming dates according their custom field date value
- Custom fields to save multiple values
- Query Posts based on custom field value
- Problem saving meta data
- Check if value exists before saving
- Echo out custom fields in comments
- Get meta value when the page is a blog archive
- Saving and using Custom Field in user settings/profile “Checkbox list”
- Search one custom field?
- Can’t save meta field value if the title not set
- Display Data From This Custom Media Upload Meta Box?
- Save values generated via API as custom meta fields
- Query postmeta values, and return multiple post_titles for common meta value
- When post is updated, custom metadata in text area field is overwritten
- change attachment custom field onChange event
- Adding custom fields to images
- How to save dynamically generated value in post type?
- wordpress simple post multi rating with post_meta and user_meta
- Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
- wp_postmeta are updated for only one page
- update_post_meta not working in action hook
- how to show this part only in the single post page?
- Custom Field: Display only if a specific key is selected outside the loop
- Display meta data from a custom field within plugin Category Grid View Gallery
- When editing a post with a custom meta box the values aren’t displaying correctly
- Hard Define Custom Field Value
- Custom fields / meta box output
- If post custom meta data is not set, show normal state
- add_post_meta insert null value into Database
- Make Custom Fields Public in JSON – API
- How do i output images from URL’s added to the same custom field key
- Retrieving custom field as shortcode
- Colecting values from custom field checkboxes and displaying them in the post
- Build Array from Input Fields question
- custom field with links
- add multiple values (array) to post meta_input
- Order by a meta field in query loop
- How can i put a custom field inside this php
- Site uses wpdb to fetch meta_keys but just displays first meta_key from a page (the post uses the same meta_key “filmmaker” more than once)
- save all acf options in one meta_value [closed]
- How to add new Metadata options (Date, Author, etc.) for Posts?
- WP Query Args – search by meta_key or title
- Saving multiple custom meta box fields
- Search for meta_query does not return any result if combined with title
- get Custom field label (select/dropdown) on front end
- SQL query based on two different custom field values
- Block Editor – Meta values not saved, meta changes to empty array on update
- What is the best way to get a different post’s custom field/postmeta with js?