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. Custom post meta field effect on the performance on the post
  3. How to get custom post meta using REST API
  4. Difference between meta keys with _ and without _ [duplicate]
  5. Orderby meta_value only returns posts that have existing meta_key
  6. What is the index [0] for on post meta fields?
  7. What is “meta_input” parameter in wp_insert_post() used for?
  8. How to enable revisions for post meta data?
  9. The “_encloseme” Meta-Key Conundrum
  10. Best way to programmatically remove a category/term from a post
  11. Using get_post_meta with new_to_publish
  12. Custom field metabox not showing in back-end
  13. So much data in postmeta
  14. Can I count the number of users matching a value in a multiple value key?
  15. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  16. How to hide meta box values from custom fields list?
  17. Auto sort the wp-admin post list by a meta key
  18. get_post_meta() unserialize issue – returns boolean(false)
  19. What is the advantage of the wp_options design pattern?
  20. Storing meta fields multiple times OR once with multi dimensional array?
  21. Allow user to create instances of custom field
  22. display specific custom fields
  23. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  24. Meta keywords and descriptions plugin for manually editing meta for each page/post
  25. passing argument to get_template_part() or a better way to code
  26. Is it possible to store arrays in a custom field?
  27. Get updated meta data after save_post hook
  28. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  29. Save HTML formatted data to post meta using add_post_meta()
  30. importing data from non-wordpress mysql db
  31. How to convert custom field value to tag
  32. Create meta boxes that don’t show in custom fields
  33. Transients vs CRON +Custom Fields: Caching Data Per Post
  34. Plugin to auto convert custom fields to tag
  35. Unable to save datetime custom meta field using update_post_meta() function
  36. Up/Down voting system for WordPress
  37. post meta data clearing on autosave
  38. Create custom field on post draft or publish?
  39. Display info from custom fields in all images’ HTML
  40. Ordering posts by anniversary using only day and month
  41. get_post_meta fields don’t show up on posts page
  42. Update meta values with AJAX
  43. How to break meta values into different items and avoid duplicates?
  44. copy attachments to another post type and change attachment url
  45. Cannot edit post meta fields with rest API
  46. ajax delete value from custom field array
  47. Save attachment custom fields on front end
  48. How to use pagination with get_post_meta
  49. Copying Custom Meta Values from existing post to a duplicate post
  50. Add a post meta key and value only if it does not exist on the post
  51. Move value of one custom field to another
  52. Order posts according to user defined order for meta values?
  53. Displaying posts with only upcoming dates according their custom field date value
  54. Custom fields to save multiple values
  55. Query Posts based on custom field value
  56. Problem saving meta data
  57. Check if value exists before saving
  58. Echo out custom fields in comments
  59. Get meta value when the page is a blog archive
  60. Saving and using Custom Field in user settings/profile “Checkbox list”
  61. Search one custom field?
  62. Can’t save meta field value if the title not set
  63. Display Data From This Custom Media Upload Meta Box?
  64. Save values generated via API as custom meta fields
  65. Query postmeta values, and return multiple post_titles for common meta value
  66. When post is updated, custom metadata in text area field is overwritten
  67. change attachment custom field onChange event
  68. Adding custom fields to images
  69. How to save dynamically generated value in post type?
  70. wordpress simple post multi rating with post_meta and user_meta
  71. Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
  72. wp_postmeta are updated for only one page
  73. update_post_meta not working in action hook
  74. how to show this part only in the single post page?
  75. Custom Field: Display only if a specific key is selected outside the loop
  76. Display meta data from a custom field within plugin Category Grid View Gallery
  77. When editing a post with a custom meta box the values aren’t displaying correctly
  78. Hard Define Custom Field Value
  79. Custom fields / meta box output
  80. If post custom meta data is not set, show normal state
  81. add_post_meta insert null value into Database
  82. Make Custom Fields Public in JSON – API
  83. How do i output images from URL’s added to the same custom field key
  84. Retrieving custom field as shortcode
  85. Colecting values from custom field checkboxes and displaying them in the post
  86. Build Array from Input Fields question
  87. custom field with links
  88. add multiple values (array) to post meta_input
  89. Order by a meta field in query loop
  90. How can i put a custom field inside this php
  91. 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)
  92. save all acf options in one meta_value [closed]
  93. How to add new Metadata options (Date, Author, etc.) for Posts?
  94. WP Query Args – search by meta_key or title
  95. Saving multiple custom meta box fields
  96. Search for meta_query does not return any result if combined with title
  97. get Custom field label (select/dropdown) on front end
  98. SQL query based on two different custom field values
  99. Block Editor – Meta values not saved, meta changes to empty array on update
  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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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