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
- Can I count every article following extracted meta value?
- Best Practice for storing aggregate data by date or other criteria?
- Block Editor – Meta values not saved, meta changes to empty array on update
- Can I exclude a post by meta key using pre_get_posts function?
- Custom field/meta populated by dropdown of existing posts?
- What is the index [0] for on post meta fields?
- Pass all custom fields through the same filter on post load?
- Add custom fields when specific templates are selected
- Save custom user meta on registration
- How to hide meta box values from custom fields list?
- update_user_meta: How many is too many?
- Search ONLY by meta key / meta values
- Using media-upload.php to upload mp3 via custom fields
- Added 20 Custom Fields. Only 10 showing in drop down
- Correct Approach for Validating Custom Field Input
- Meta keywords and descriptions plugin for manually editing meta for each page/post
- Query meta field using between
- How to add/save Custom Field in user settings/profile “Checkbox list”
- How to add dynamically the main parent pages’s custom fields and their values to all sub-pages?
- Delete post based on a custom field?
- How to make custom comment fields required and message field not required
- Display info from custom fields in all images’ HTML
- Update meta values with AJAX
- How can I migrate all of my custom field thumbnails to the built-in post featured image?
- Multiplile values checkbox or select in custom meta box
- Front-end update_post_meta with ajax
- How to use query_posts() with a date filter on a custom field?
- Login & Register & Custom details WITHOUT plugin
- Compare WP Custom Field date
- Escaping Quotes
- Deleted pages showing up when querying for child pages
- Count how many posts have a custom field set
- wp_editor removes paragraph from custom meta box
- Any way to include custom fields in WP_Query results?
- Duplicate posts being displayed when querying Custom Fields
- using multiple meta_key and meta_value in query_posts
- How to validate custom field on lost password form before the user id field?
- Json api does not return all metadata
- Use custom field as a variable
- ACF: How to get the full field name (meta_key) by a field key?
- Woocommerce: Custom fields and email shortcodes, ec_custom_field
- Tweak Meta for Post to work it for Pages also
- global function to apply filter to custom field
- How to add a new meta key and assign timestamp to posts
- Adding an editable field to template?
- Transferring author information from a custom field to a proper author
- How to select posts from multiple categories and metavalues?
- Print custom field in Query Loop block
- Is there a simpler version of WP Media?
- Order RSS content by an advanced custom field value
- Advanced search by two criteria – sort by location and date (ascending or descending)
- modify wordpress caption shortcode
- Seach custom post type posts only by meta fields?
- UPDATE on SELECT results. A SQL query to swap Author with Meta Box value
- Alter main archive, to show posts with meta as last
- Add microdata from schema.org [closed]
- Displaying multiple URLs as custom field values
- Linking Custom Fields to Database Records
- Collect user custom field in product page woocommerce
- Truncating characters in Advanced Custom Fields works some places but not others?
- Custom fields – get_post_meta giving null
- Replacing the deprecated function the_meta