You need to pass the $post_id
into the get_the_content()
:
function add_custom_fields($post_id) {
global $post;
$metadescription = wp_trim_words( get_the_content($post_id), 55 );
add_post_meta($post_id, 'meta_description', '' . $metadescription . '', true);
}
add_action('wp_insert_post', 'add_custom_fields');
Related Posts:
- WP_Query – Order results by meta value
- Custom post meta field effect on the performance on the post
- Difference between meta keys with _ and without _ [duplicate]
- Orderby meta_value only returns posts that have existing meta_key
- Can I query custom meta data through WP_Query
- Having different sidebar content for MANY pages?
- Add custom objects/entities to WordPress
- Change behavior of “Insert into Post” based on attachment metadata
- Sort posts by custom field numeric value using dropdown
- How to position a custom field before the editor
- How can I display all values of a custom field from posts with a certain value of another custom field or from certain post types?
- Is there a way to do multiple ordering on a multiple meta_query?
- searching in custom meta field
- How to add upload field in a custom taxonomy?
- Display thumbnail from custom field
- Plugins won’t recognize my plugin’s hidden custom fields
- Store JSON in a custom field
- If value present, order posts by two consecutive custom fields
- Custom contact form 7 select with custom values [closed]
- limit amount of photos uploaded per cpt post
- Save page data to an xml file
- Create Posts using Import>RSS/WXR/XML and pass values to Custom Fields
- Best way to add custom / magic / flutter fields into RSS feed
- Setting orderby to a custom field using pre_get_posts
- How to save a ToggleControl value in a meta field?
- Add WYSIWYG to Image Description field
- How to get multiple checkboxes in one meta field
- Adding Custom Fields to Search
- How to Display Custom Meta Box only on Specific Page IDs
- Get custom field label
- Show ACF fields only on certain page in the backend
- How do I use Ajax to build a dropdown of custom fields based on a post selected in previous dropdown?
- Register rest field for specific user
- Custom Field Suite A little problem
- Save the_content into custom field
- How make a custom search on backend in WordPress without plugin?
- Create Multiple File Upload Metabox in WordPress
- WP_User_Query pulling ACF to loop
- how to put a custom field value in variable
- get_posts that haven’t been assigned a specific custom field
- How to add the image URL from an external RSS feed and insert into a custom field?
- how to upload a image from frontend with wp_insert_post and also update_post_meta?
- My custom backend codes shows up when i try to view my website
- Advanced Custom Fields dynamic update_field
- Custom Profile Fields move from BBpress to BuddyPress
- How can I output a list of values for a custom field, and posts with those values?
- Insert a custom field into a shortcode and use it in post(s)
- Sort alphabetically by custom field
- Why orderbyb meta_value_num won’t affect the generated SQL Query order?
- I need a “Choose from existing content” popin
- For homepage images (for small business website), is it better to use custom fields or post_thumbnail?
- Sorting editor screen items
- get post id using custom filed value
- Query_posts with custom field meta value
- Passing meta_box string to post__in?
- Can data from a Custom Field data be used by a shortcode on a per page/post basis?
- How can I modify RSS item titles to be either the title or a custom meta field?
- Avoiding ACF get_field and returning to core WordPress function
- Display custom field value part by part?
- WordPress built in custom fields don’t validate or sanitize? Is there a way to fix this?
- How can I hide custom field from users used for caching response from external api?
- How do i get the attached images with custom value checked?
- WordPress colorpicker save both hex and RGB
- Cannot save underscore custom fields in one wordpress installation using xmlrpc and underscores
- Can’t get video meta from wp_read_video_metadata()
- Best way to contruct a global custom field?
- Diamond question mark in text after migrating content
- Display posts with empty custom field
- How to write specific HTML code with a specific custom field? [closed]
- How to style posts selecting a CSS post_class (added through custom_fields?)?
- Custom Fields Question
- Meta query relation ‘OR’ not working as expected
- How to hide custom fields added by a plugin?
- Add custom data (field) to sidebar widgets for later display
- How do I convert all custom_field php timestamps in the database to js timestamps?
- Image upload and path to custom field
- Create a new custom field for all posts based on current custom field
- Display custom field value as a mailto: link
- Display custom field only if it has a value
- Make separate text boxes for separate WordPress Custom Fields
- Need to search a custom field (ingredients, one long string per post), but want it to allow phrases/non-exact matches
- Listing posts with a value in a custom field
- Using Customizer API vs Custom Meta Box for custom content
- Sort by an ACF field in a tax_query
- How do I display an article using a WordPress custom field?
- WordPress admin area: select box with 12.000+ options
- to create a custom post type with additionnal url field such as link to social network and an email field
- Load one page with parent and child pages
- Why can’t I get the correct post permalink
- Query Multiple meta
- Ordering posts by custom fields
- Show message if statement is false – foreach
- Order by custom field in query multiple
- Returning website screenshot based on Custom Field
- Echo text if field under user_meta is empty with get_users()
- Filtering posts by WORD in custom field
- Cannot Hide Google Map if custom field is blank
- Add CSS class to posts with certain meta key
- Modal pop-up HTML code works on other sites or HTML viewers but not in the custom HTML block within a wordpress page?
- Automatically changing a posts status to draft based on magic fields [closed]