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?
- What is the index [0] for on post meta fields?
- Best way to programmatically remove a category/term from a post
- Custom field metabox not showing in back-end
- 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?
- What is the advantage of the wp_options design pattern?
- Storing meta fields multiple times OR once with multi dimensional array?
- display specific custom fields
- Meta keywords and descriptions plugin for manually editing meta for each page/post
- Is it possible to store arrays in a custom field?
- Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
- importing data from non-wordpress mysql db
- How to convert custom field value to tag
- Transients vs CRON +Custom Fields: Caching Data Per Post
- Unable to save datetime custom meta field using update_post_meta() function
- Create custom field on post draft or publish?
- Display info from custom fields in all images’ HTML
- get_post_meta fields don’t show up on posts page
- Update meta values with AJAX
- copy attachments to another post type and change attachment url
- Cannot edit post meta fields with rest API
- Add a post meta key and value only if it does not exist on the post
- Order posts according to user defined order for meta values?
- Custom fields to save multiple values
- Function to change meta value in database for each post
- Get aggregate list of all custom fields for entire blog
- wp_handle_upload error “Specified file failed upload test” but still creates attachment?
- Default WordPress taxonomy (Tag) – How to add a custom field to form and save it to the database
- using multiple meta_key and meta_value in query_posts
- Adding custom fields (post meta) before/during wp_insert_post()
- Get specific custom field keys from a post and put into an array
- MySQL Query that looks for post with Custom Field, then changes Category
- ACF: How to get the full field name (meta_key) by a field key?
- post meta getting deleted on save
- filtering custom post types via meta data drop down
- How to add a new meta key and assign timestamp to posts
- If meta key exists in get posts function otherwise create it
- Custom field not updating when value is empty
- meta_compare seems to be treating values as strings instead of integers as expected
- Limit the number of acf content when displaying in post loop [closed]
- Read / Watch / Listen times – meta
- How to add custom metadata text box dropdown to sidebar in Gutenberg editor for all post types
- How do I Implement Atomic Update of Post Metadata?
- Why is my Custom Meta Box Field Inputs NOT saving?
- Get registered custom fields or post meta even if empty
- Displaying multiple URLs as custom field values
- Show values of custom post meta on ‘Add new post’ page?
- Custom post meta field effect on the performance on the post
- get_posts in meta box dropdown not showing latest posts
- Limits, not all post are showen when querying for posts by view count
- Display Custom Meta Box Field Only If Value is Present
- Ordering posts by custom field named “date” in backend
- Stop sending email everytime I updates my post
- Best way to store everyday post views?
- edit_tag_form_fields is depricated but tag_edit_form_fields doesn’t work
- Unable to get specific value from post meta
- Custom meta is not being saved
- How to use media upload on metabox post page without breaking TinyMCE?
- Let’s Create Custom Field Template Documentation
- Branch made by several custom values
- Looping inside block return
- WordPress creates new lines in postmeta table on post update
- User customising position of WordPress Featured Image
- Can I save post meta programatically without setting metaboxes?
- Insert image into sub-field with update_post_meta
- How to use conditional statement with custom field
- Meta box values are displayed on Custom Fields list. Is it possible to hide them?
- If metabox has content display content
- Best way to achieve multiple links in a post title
- Display Meta Data with HTML?
- How can I add/update post meta in a admin menu page?
- Get author total post votes from post meta
- Group Posts By Custom Meta Value: Date
- custom filed from post in the side bar
- Automatically Add Custom Fields Value as Tags
- How to display custom fields in hestia theme
- How to speed up post list slowed by update_meta_cache()?
- WordPress Blocks, setAttributes not saving
- Adding Facebook’s image and meta description retrieval capabilities to a WordPress post
- SQL query to change the value of a Custom Field
- Custom meta POST request fired twice when updating a post in Gutenberg
- Add custom field information to source meta data
- Update custom field on page specific to logged in user
- Create Meta boxes dynamically
- Delete custom meta
- Problem saving meta data
- Check if value exists before saving
- Get meta value when the page is a blog archive
- Saving and using Custom Field in user settings/profile “Checkbox list”
- change attachment custom field onChange event
- wordpress simple post multi rating with post_meta and user_meta
- wp_postmeta are updated for only one page
- Custom fields / meta box output
- Colecting values from custom field checkboxes and displaying them in the post
- Build Array from Input Fields question
- 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)
- What is the best way to get a different post’s custom field/postmeta with js?