building on keatch’s answer you only need to trim if its longer the 25 chars so:
$trim_length = 25; //desired length of text to display
$custom_field = 'my-custom-field-name';
$value = get_post_meta($post->ID, $custom_field, true);
if ($value) {
if (strlen($value) > $trim_length)
$value = rtrim(substr($value,0,$trim_length)) .'(...)';
echo $value;
}
Related Posts:
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Max length of meta_value
- SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
- 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?
- get_pages sort alphabetically by meta value
- Assign/update the custom field value for all posts
- Order by custom field date with ASC order
- How to break meta values into different items and avoid duplicates?
- WP_query : meta_key with custom rule for specific value
- How to sort category by custom field value
- Query post order by post and desc not working
- How to wrap meta values seperated by comma in ? [closed]
- How to create a Custom Meta Box with Name/Value Admin User Input Fields?
- Run a check for multiple meta key values
- Filter by custom field (meta_key) using JSON API
- Removing link ” from ” on meta_value in custom feilds
- Sort alphabetically by custom field
- pre_get_posts : only get posts by wp_usermeta value
- meta_value and meta_key filtering returning no posts [closed]
- IF Custom field value equals ZERO
- List custom field values in alphabetical order without repetition
- How to update a custom field in all posts with the value of another custom field in the same post?
- Update post meta custom field using block editor
- How to add custom filed value after in wp post title
- Sortable Custom Columns not sorting correct
- query_posts with meta_value
- Show array of meta_value in Edit Post Coloum
- Making WP_Query limit results by date before today where date is a meta_query
- User query – getting values for custom meta keys/fields
- get posts based on non-single metadata
- Set class if a meta value is set within post archive
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Create Shortcode shows only posts with custom_field meta
- 4 Unique Random Posts based on Custom Field Values
- Custom Field: Display only if a specific key is selected outside the loop
- WP Query Args – search by meta_key or title
- Saving multiple custom meta box fields
- get Custom field label (select/dropdown) on front end
- Where are custom field values stored in the database
- Using TinyMce with textareas in meta boxes on custom post types
- How can I fetch CSS from JSON WP REST API response
- How to set a default meta value for custom field
- Create meta boxes that don’t show in custom fields
- How To Create a Metabox of HTML Content with Instructions For Editors When Editing a Post or Page?
- wp_editor in add_meta_boxes does not show gallery
- Calling Specific Pages with wp query Part II
- How do I assign this filter to a variable? (Appending php & markup to the_content)
- Copying Custom Meta Values from existing post to a duplicate post
- Deleting a custom field field
- custom field to always to .get_the_title()?
- Displaying posts with only upcoming dates according their custom field date value
- How to filter a dd/mm/yyyy date from a custom field in a query
- List posts with common custom field value
- Importing users to Buddypress with custom fields
- Is it bad to use a lot of Custom Meta Fields?
- How can I pass a variable set by ACF to header.php?
- Meta_query is not working on Elementor Custom Query Filter [closed]
- Add Custom Field to a template page backend
- custom field not saved
- Getting the ID of any image for use in functions.php
- How to schedule a custom field value update?
- Advanced search for meta fields
- Woocommerce Product Custom Select List (not variation)
- How to find a post using XML-RPC without knowing ID
- Populate Javascript code with value from WordPress Custom Field?
- Limit of char count in WP custom fields
- how to make nsfw post with thumbanil
- Specific coditional usage [closed]
- How to I make my post title link to a custom field
- How can I check if a custom field was updated?
- Get custom fields without _edit_last, _edit_lock, _wp_page_template and _visual-subtitle
- award points to a user each time they update their cpt post
- TinyMCE custom button retrieve value from custom field
- Update post meta data (custom field) by post link
- Changing order in which custom fields appear in dashboard
- Let Users Filter Posts by Custom Fields
- Retrieving custom field value with get_post?
- Run Function if Order Meta Exists – WooCommerce
- Custom Query: query by post custom meta data
- Using Custom Fields to Trigger Specific Actions on Saving a Post?
- trying to add extra field using hooks
- Can’t set custom meta fields for a post
- Hiding Dropdown Fields
- Custom fields with wordpress
- Link fields in User Admin list
- what would be a good example of a php dynamic code to display contents of textarea?
- Get file size from ACF repeater field
- Append custom field items to content from plugin
- Set Value To Custom Field While Submit
- Show or hide lang=”ur” in main element
- How to use a custom field for search engine optimization
- Fetch data from a WP page with same name as current username
- Getting content from custom fields of different pages on a single page
- When editing a post with a custom meta box the values aren’t displaying correctly
- How to get the value of particular get $meta value in wordpress
- custom field as a boolean with a checkbox?
- Hiding custom fields when content is empty [closed]
- Website that sells statistics
- Extract array from custom field
- Match submitted array fields with the MYSQL database fields to update them correctly in PHP