Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Save all the post tags inside a custom field

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:

  1. Can I exclude a post by meta key using pre_get_posts function?
  2. What is the index [0] for on post meta fields?
  3. Best way to programmatically remove a category/term from a post
  4. Custom field metabox not showing in back-end
  5. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  6. How to hide meta box values from custom fields list?
  7. What is the advantage of the wp_options design pattern?
  8. Storing meta fields multiple times OR once with multi dimensional array?
  9. display specific custom fields
  10. Meta keywords and descriptions plugin for manually editing meta for each page/post
  11. Is it possible to store arrays in a custom field?
  12. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  13. importing data from non-wordpress mysql db
  14. How to convert custom field value to tag
  15. Transients vs CRON +Custom Fields: Caching Data Per Post
  16. Unable to save datetime custom meta field using update_post_meta() function
  17. Create custom field on post draft or publish?
  18. Display info from custom fields in all images’ HTML
  19. get_post_meta fields don’t show up on posts page
  20. Update meta values with AJAX
  21. copy attachments to another post type and change attachment url
  22. Cannot edit post meta fields with rest API
  23. Add a post meta key and value only if it does not exist on the post
  24. Order posts according to user defined order for meta values?
  25. Custom fields to save multiple values
  26. Function to change meta value in database for each post
  27. Get aggregate list of all custom fields for entire blog
  28. wp_handle_upload error “Specified file failed upload test” but still creates attachment?
  29. Default WordPress taxonomy (Tag) – How to add a custom field to form and save it to the database
  30. using multiple meta_key and meta_value in query_posts
  31. Adding custom fields (post meta) before/during wp_insert_post()
  32. Get specific custom field keys from a post and put into an array
  33. MySQL Query that looks for post with Custom Field, then changes Category
  34. ACF: How to get the full field name (meta_key) by a field key?
  35. post meta getting deleted on save
  36. filtering custom post types via meta data drop down
  37. How to add a new meta key and assign timestamp to posts
  38. If meta key exists in get posts function otherwise create it
  39. Custom field not updating when value is empty
  40. meta_compare seems to be treating values as strings instead of integers as expected
  41. Limit the number of acf content when displaying in post loop [closed]
  42. Read / Watch / Listen times – meta
  43. How to add custom metadata text box dropdown to sidebar in Gutenberg editor for all post types
  44. How do I Implement Atomic Update of Post Metadata?
  45. Why is my Custom Meta Box Field Inputs NOT saving?
  46. Get registered custom fields or post meta even if empty
  47. Displaying multiple URLs as custom field values
  48. Show values of custom post meta on ‘Add new post’ page?
  49. Custom post meta field effect on the performance on the post
  50. get_posts in meta box dropdown not showing latest posts
  51. Limits, not all post are showen when querying for posts by view count
  52. Display Custom Meta Box Field Only If Value is Present
  53. Ordering posts by custom field named “date” in backend
  54. Stop sending email everytime I updates my post
  55. Best way to store everyday post views?
  56. edit_tag_form_fields is depricated but tag_edit_form_fields doesn’t work
  57. Unable to get specific value from post meta
  58. Custom meta is not being saved
  59. How to use media upload on metabox post page without breaking TinyMCE?
  60. Let’s Create Custom Field Template Documentation
  61. Branch made by several custom values
  62. Looping inside block return
  63. WordPress creates new lines in postmeta table on post update
  64. User customising position of WordPress Featured Image
  65. Can I save post meta programatically without setting metaboxes?
  66. Insert image into sub-field with update_post_meta
  67. How to use conditional statement with custom field
  68. Meta box values are displayed on Custom Fields list. Is it possible to hide them?
  69. If metabox has content display content
  70. Best way to achieve multiple links in a post title
  71. Display Meta Data with HTML?
  72. How can I add/update post meta in a admin menu page?
  73. Get author total post votes from post meta
  74. Group Posts By Custom Meta Value: Date
  75. custom filed from post in the side bar
  76. Automatically Add Custom Fields Value as Tags
  77. How to display custom fields in hestia theme
  78. How to speed up post list slowed by update_meta_cache()?
  79. WordPress Blocks, setAttributes not saving
  80. Adding Facebook’s image and meta description retrieval capabilities to a WordPress post
  81. SQL query to change the value of a Custom Field
  82. Custom meta POST request fired twice when updating a post in Gutenberg
  83. Add custom field information to source meta data
  84. Update custom field on page specific to logged in user
  85. Create Meta boxes dynamically
  86. Delete custom meta
  87. Problem saving meta data
  88. Check if value exists before saving
  89. Get meta value when the page is a blog archive
  90. Saving and using Custom Field in user settings/profile “Checkbox list”
  91. change attachment custom field onChange event
  92. wordpress simple post multi rating with post_meta and user_meta
  93. wp_postmeta are updated for only one page
  94. Custom fields / meta box output
  95. Colecting values from custom field checkboxes and displaying them in the post
  96. Build Array from Input Fields question
  97. Order by a meta field in query loop
  98. How can i put a custom field inside this php
  99. 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)
  100. What is the best way to get a different post’s custom field/postmeta with js?
Categories custom-field Tags custom-field, post-meta, tags
Get access to variable from previous pageview, excluding ajax-calls
How to add registration date and last login date to user list page

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress