• Website http://www.henleyprobate.org.uk uses wordpress 3.8.1 and plugin Advanced Custom Fields 3.5.0. I am aware that newer versions are available, but there were problems updating and it seems preferable to stick with versions that generally work well until the problems are understood.
    The website stores C18th wills as custom posts. Post type ‘ewo’ has information about executors, witnesses and others associated with a will. The custom field ‘relationship’ holds the relationship if any with the testator. It all seems to work, but exceptionally, the relationship is displayed as a text string of the form a:1:{i:0;s:6:”Friend”;} when “Friend” should have been displayed. Deleting the ewo post in the dashboard and re-creating it seems to resolve the problem. But why?
    The code that displays the relationship is

    '   <?php
        $args = array(
            'post_type' => 'ewo',
            'post_status' => array('publish', 'draft', 'pending'),
            'orderby' => 'ID',
            'order' => 'ASC',
            'nopaging' => 'true',
            'meta_query' => array(
                  array (
                      'key' => 'will_id',
                      'value' => $will_id
                  )
              )
          );
        $query_others= new WP_Query($args);
        if ($query_others->have_posts()) {
    		echo "<h2>Executors, Witnesses and Court Officials etc.</h2>";
    		?><table><?php
    		while($query_others->have_posts()) {
    			$query_others->the_post();
    			$other_id = $query_others->post->ID;
    			$custom_fields = get_post_custom($other_id);
    			$role = $custom_fields['role'];
    			$other_first_name = $custom_fields['first_name'];
    			$other_last_name = $custom_fields['last_name'];
    			$relationship = $custom_fields['relationship'];
    			$additional_text = $custom_fields['additional_text'];
    			?>
    			<tr>
    				<td class="will-label"><?php echo $role[0] ?>: </td>
    				<td class="will-field"><?php echo $other_first_name[0] . " " . $other_last_name[0] ?></td>
    			</tr><?php
    			if (!empty($relationship[0] )) {
    				?><tr><td class="will-label">Relationship: </td><td class="will-field"><?php echo $relationship[0] ?></td></tr><?php
    			}
    			if (!empty($additional_text[0] )) {
    				?><tr><td></td><td class ="will-additional"><?php echo " (" . $additional_text[0] . ")"; ?></td></tr><?php
    			}
    		}
        } ?><!-- end of if executor etc posts -->
          </table>'

    Theproblem can be seen in the will of Samuel Bolton:
    http://www.henleyprobate.org.uk/?will=samuel-boulton-27-june-1799
    When this exceptional behaviour happens, it affects a few of the ewo posts for the one will.

Viewing 4 replies - 1 through 4 (of 4 total)
  • It appears that the relationship is stored as a ‘serialized’ string in those instances. You can check for that and unserialize like this (UNTESTED):

    $relationship = $custom_fields['relationship'];
    if ( is_serialized($relationship) ) {
       $relationship = unserialize($relationship);
    }
    Thread Starter jgtjones

    (@jgtjones)

    Thanks for the suggestion, but inserting that code made no difference. Using:

    if ( is_serialized($relationship) ) {
        ?><p>serialized</p><?php
        $relationship = unserialize($relationship);
    } else {
         ?><p>Not serialized</p><?php
    }

    indicated that the data was not serialized.
    Any further thoughts?

    My mistake. Try replacing this:

    <?php echo $relationship[0] ?>

    with this:

    <?php echo (is_serialized($relationship[0])) ? unserialize($relationship[0]) : $relationship0]; ?>

    Thread Starter jgtjones

    (@jgtjones)

    Thanks for the revision.
    The problem goes away by simply opening the post to edit it and then saving. Don’t know why the earlier save was serialized and the later one not.
    Decided to correct the data rather than test for serialized when displaying this field.
    Removed much of the tedium by writing a script to identify all posts with field $relationship[0] == “a:1:…” and including an edit post link. For posterity and anyone else finding a similar problem here is my code to be read in conjunction with above.
    `<?php
    if (!empty($relationship)) {
    if ($relationship[0] != ‘None’) {
    ?><span class=”ewo-text”> and <?php echo $relationship[0]; ?></span><?php
    if ($current_user->display_name == ‘Administrator’) {
    if (substr($relationship[0], 0, 4) == ‘a:1:’) {
    ?><span class = “ewo-error”>(Will Id = <?php echo $will_id[0]; edit_post_link(‘edit’, ‘ ‘, ‘.’, $id); ?>)</span><?php
    }
    }
    }
    }`
    By way of explanation, the edit link appears only to the ‘Administrator’ user, the will_id is displayed for confirmation and the ‘None’ role is not displayed, useful for me but irrelevant in general. the a:1: is appropriate only for a single term.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom field "Friend" displays as a:1:{i:0;s:6:"Friend";}’ is closed to new replies.