A suggestion I have -- when creating a post, if a custom field is left blank, the empty string shouldn't be stored in the postmeta table.
Great job so far. Looking fwd to the next release =)
A suggestion I have -- when creating a post, if a custom field is left blank, the empty string shouldn't be stored in the postmeta table.
Great job so far. Looking fwd to the next release =)
I second that! Is there a way to change this easily?
or could you give me any help with creating a if,else string?
The following works quite fine sometimes, but not on all the custom fields
<?php $key="Role"; $values = get_post_custom_values($key); if ( isset($values) ) { ?><?php echo $values[0]; ?><?php } elseif ( empty($values) ) { ?><?php echo 'n/a'; ?><?php } ?>
Anybody?
I have had a look at the source code of RCCWP_Post.php and compared it to the respective part of the rc-custom-field-gui.class.php file.
From the Custom Write Panel:
if (!empty($rawCustomFieldName))
{
$customFieldName = $wpdb->escape(stripslashes(trim(RC_Format::GetFieldName($rawCustomFieldName))));
$customFieldValue = $_POST[$rawCustomFieldName];
delete_post_meta($postId, $customFieldName);
if (is_array($customFieldValue))
{
foreach ($customFieldValue as $value)
{
$value = stripslashes(trim($value));
add_post_meta($postId, $customFieldName, $value);
}
}
else
{
$value = stripslashes(trim($customFieldValue));
add_post_meta($postId, $customFieldName, $value);
}
}
else
{
delete_post_meta($postId, $customFieldName);
}
From the Custom Field GUI file:
$meta_value = stripslashes(trim($_REQUEST[ \"$name\" ]));
if( isset( $meta_value ) && !empty( $meta_value ) ) {
delete_post_meta( $id, $title );
if( $data[ 'type' ] == 'textfield' ||
$data[ 'type' ] == 'radio' ||
$data[ 'type' ] == 'select' ||
$data[ 'type' ] == 'textarea' ) {
add_post_meta( $id, $title, $meta_value );
}
else if( $data[ 'type' ] == 'checkbox' )
add_post_meta( $id, $title, 'true' );
}
else {
delete_post_meta( $id, $title );
}
I am really bad with core PHP stuff. So how do I adapt the RCCWP_Post.php to delete the meta data and not create a custom field for a post if it is left blank? Any help would GREATLY be appreciated!
You must log in to post.