How to display custom fields from a plugin

To retrieve a post (or product) custom field, it depends on where you want to display it. To get a single custom fields: // in your product loop, $reserved_price = get_post_meta($post->ID, ‘_auction_reserved_price’, true); echo $reserved_price; if you want to get an array of all your plugin custom fields. You must loop trough all meta for … Read more

Run str_replace on title and save the output to a custom field

the_title_rss() outputs its value straight away so it can’t be used in a function like that, you would have to use get_the_title_rss() Or alternatively the_title_rss() has a filter we can hook in to and return your shortened title is possible. (You would add this to your functions.php) function gg_short_title_rss($title) { // This can return false, … Read more

Display Repeatable Meta Box Content

Here’s a tested and working version of the template code, which displays the repeatable $emergency_contact_meta correctly: $member_contact_meta = get_post_meta( get_the_ID(), ‘tcp’, true ); echo ‘<strong>Phone: </strong>’ . $member_contact_meta . ‘<br />’; $emergency_contact_meta = get_post_meta( get_the_ID(), ‘repeatable_fields’, true); if ( $emergency_contact_meta ) { echo ‘<strong>Emergency Contacts:</strong><br />’; foreach ( $emergency_contact_meta as $emergency_contact_metas ) { echo ‘<strong>’ … Read more

Why does this update_post_meta function not delete the custom field itself?

You’re looking for delete_post_meta($post_id, $meta_key, $meta_value); Parameters $post_id (integer) (required) The ID of the post from which you will delete a field. Default: None $meta_key (string) (required) The key of the field you will delete. Default: None $meta_value (mixed) (optional) The value of the field you will delete. This is used to differentiate between several … Read more

Display custom field on 404 page outside loop

You should not hide functionality in a template file. Templates are dumb, you don’t run unit tests on them normally. I’d recommend to move the logic to a separate function in your functions.php: function header_class( $default=”white” ) { $post = get_post(); // 404 pages, empty archives (user, taxonomy, date) if ( empty( $post ) ) … Read more