You have to consider that you’re dealing with substr()
a string related function as the str in the function name indicates. That does mean that the parameter $string
you give actually has to be of the type string
.
get_post_meta()
on the other hand does just give you back whatever type you saved in the first place. So it isn’t guaranteed that your getting back a string – you have to make sure of that yourself. Which you can do by type casting the value, variable you receive.
So far so good, let’s put it together:
$custom_field = (string) get_post_meta( $post->ID, "CUSTOMFIELD", true );
echo substr( $custom_field, 0, -3 );
Related Posts:
- How to update custom fields using the wp_insert_post() function?
- Adding custom input for data attribute in insert media modal
- If Custom Field is empty don’t display div
- Custom Meta Field – Youtube embed
- How can i create a function to get youtube video time
- Getting movie and serial on actor page
- Match checkbox data with page title to show certain items
- Print html when custom field has value inside while loop
- Update WordPress Custom Field with AJAX on cached page
- Geocoding an Exploded Custom Field Array
- How to Explode a Textarea Field and Echo each line separately, wrapped with HTML
- WooCommerce: update custom fields after checkout validation failure
- how to increase custom post value by one most efficiently?
- Sum custom field values of particular taxonomy
- Importing hard coded custom field into acf field
- Firing schema via code in functions.php doesn’t work
- How can I add extra word in permalink when someone click download button?
- Seach custom post type posts only by meta fields?
- how to retrieve a value if a checkbox is checked
- Two queries for a WP_User_Query search work perfectly apart, but not together
- conditional logic for front-end custom field edits
- Automatic Shortcode Creation with Custom Fields [closed]
- Custom field values to taxonomy terms
- How to add specific meta tags to head of cart and checkout pages in woocommerce?
- Which PHP page is the Default Posts Page
- Non-Closing PHP Query in WordPress Loop
- How to check if a PHP string is different than meta field?
- Display custom field on 404 page outside loop
- Why does this update_post_meta function not delete the custom field itself?
- How to show/hide php table rows based on the content of custom fields
- Only show image from custom field when present
- how to get serialized post meta
- Hide Heading if ACF Field is empty
- Custom meta box values are not getting saved for my custom post type
- WP_Query: getting posts where custom field exists
- How to show meta value code HTML after x paragraph
- Creating an image from a custom field
- User Meta Value not echoing despite Var_Dump Showing correct string
- WordPress loop by meta key that is an array? and how loop multiple arrays
- Problem with adding custom CSS class to image in ACF Photo Gallery plugin [closed]
- Concatenate Custom Field Value & HTML Value
- Output custom text field as unordered list
- Conditional featured image with youtube thumbnail
- Order a WP_Query by meta value where the value is an array
- Unable to render custom field after attempt to generate a list of recent post in page template
- Add a custom class to the body tag using custom fields
- Conditional On custom field plugin metabox
- Filter unique custom field value based on custom taxonomy category or other custom field
- Meta boxes only displayed when editing normal (default wp post_type) posts
- WordPress stripping out custom field tags
- Can ‘Custom Field’ data be inserted into this Short Code?
- Using an “IF” statement based on the existence of custom field
- Query pulling a single post per month
- Display additional user fields
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- Updating Metadata with Shortcode
- How do you save the values from custom fields to a products data
- Add a “custom field” to a category that can be retrieved when viewing the category page with get_post_meta
- Trying to update Woocommerce meta values
- Is it possible to update the dataset using update_post_meta
- How to update custom fields when post is published?
- Hide a div if the fiels is empty
- Setting up a cron job to auto update a custom field
- How to Call on WordPress Custom Fields without a Plugin
- Inserting a class on before_widget if checkbox is checked
- Query on a repeater date (acf)
- What is the correct way to search 3 custom fields only in WordPress?
- Save custom field on WP_List_Table
- How do I get the value of a current user’s custom field?
- Trying to retrieve meta values from three different meta keys and display in rows
- WP post meta – for loop inside for loop
- custom fields anchor points php
- Store custom field’s multiple values in one user meta key
- Get field in readable word
- WooCommerce multiple custom fields code
- Updating Lat and Lng of posts automatically gives sporadic results
- WP_query meta_query slow with OR and DATES
- Get meta_query value by user meta array
- meta field for numerous links
- Include a custom field in mysql query
- Display Content Based on Custom Field Value
- divide custom field values in div every two values
- Showing custom field contents without listing description
- How to exclude post from being queried based on custom meta value
- How to link a word comprised of a custom field with another?
- Custom field in title
- How to use custom fields to replace top-level parent title with an image using wp_list_pages?
- Posts sortable column not sorting properly for custom field numbers
- Search result page – display values from the result’s metaboxes
- Query posts by custom fields (object post)
- ACF Date fileds to Age Convert [closed]
- Save custom field value to variable for conditional – why is this not working? [closed]
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- I want to show image from custom field image on my custom page template
- How do I organize posts based on their taxonomy?
- Search custom post type posts only by meta fields?
- How to pass value to add_filter wpcf7_form_tag from another function?
- Custom Admin Menu Report for Specific User ID
- Shortcode Displays 2 times
- ACF number less than comparison not working