Hide / Show Custom field depending of the page ID (Magic Field 2)

You can remove meta boxes with the remove_meta_box function: function wpse50430_remove_meta_boxes() { // make sure we’re on an admin screen and `post` is set if( !is_admin() && !isset( $_GET[‘post’] ) ) return; if( $_GET[‘post’] == 99 ): // editing page ID 99 remove_meta_box( ‘pageparentdiv’, ‘page’, ‘normal’ ); endif; } add_action( ‘admin_menu’, ‘wpse50430_remove_meta_boxes’ ); To remove … Read more

get_post_meta returns 0

Change $single back to false, e.g.: <?php $name_text = get_post_meta( 65, ‘name_text’ ); ?> Why? If set to true then the function will return a single result, as a string. If false, or not set, then the function returns an array of the custom fields. This is not intuitive. For example, if you fetch a … Read more

using custom fields on content.php file of my theme

empty will only take variables passed by reference. so empty(some_function()) will never work. See the php docs for more information. <?php if (get_custom_field_value(“signature”,””)) : ?> &mdash; <?php the_category( ‘<span>/</span>’ ); ?> <?php endif; ?> You’re better off just checking for the boolean, like above. The get_custom_field_value function already takes care of making sure you get … Read more

Editing custom fields for comments

I think you’ve way over-complicated things. Assuming private is a checkbox, just check for it being set, and act accordingly. With form $_POST data, a checkbox will send its value if checked, and will send nothing if not checked: if ( isset( $_POST[‘private’] ) ) { update_comment_meta( $comment_id, ‘private’, ‘private’ ); } else { delete_comment_meta( … Read more