Best filter to use for modifying custom fields on a post?

Ok, this is actually about the output as you said in your comment. I suppose you know, you can do modification like this: // assumed a single result is returned as string $your_post_meta = get_post_meta( get_the_ID(), ‘your_post_meta’, true ); // lets add something $your_modified_post_meta=”My post meta: ” . $your_post_meta; So far so obvious I would … Read more

Add custom fields to existing posts (admin pages)

As Andreas Krischer suggested, I fixed using an script to update all the old values and then only using the wp_insert_post to create the custom field for the new posts. The script that I used: INSERT INTO wp_postmeta( post_id, meta_key, meta_value ) SELECT wp_posts.ID, ‘municipi’, ” FROM wp_posts WHERE wp_posts.post_status=”publish” AND wp_posts.post_type=”post” Here I’m updating … Read more

Warn user that data may be lost for custom pages

you have to make a javascript code similar to this… jQuery(function ($) { name = $(‘#name’).val(); $(‘#name’).data(‘old_value’,name); window.onbeforeunload = function () { if ($(‘#name’).data(‘old_value’) !== $(‘#name’).val()) return ‘You have unsaved changes!’; } }); here’s a demo page… try closing the page after changing the value of the textbox there…

Display custom field value part by part?

Per comments just trim the $colors before use: if ( get_post_meta( get_the_ID(), ‘hex_colors’, true ) ){ $colors = get_post_meta( get_the_ID(), ‘hex_colors’, true ); $colors = explode( ‘ ‘ , trim( $colors ) ); foreach( $colors as $color ) { echo ‘<div>’, $color, ‘</div>’; } }

List all unique custom field values?

From what I understand I think you can try something like: SELECT meta_value, COUNT(post_id) as count FROM $wpdb->postmeta WHERE meta_key = ‘authors’ GROUP BY meta_value HAVING count >= 20 ORDER BY meta_value; Let me know if this works for you!