Tuesday, 10 September 2013

I wish to output a string from an array in PHP

I wish to output a string from an array in PHP

I've got a plugin for Wordpress that lets you reorder posts. This plugin
displays the post_name and is surrounded by a drag n' drop box.
I wish to change the format of the
"post_name"
to
"post_name - custom field"
I have tried changing the PHP to the following:
$output .= $indent . '<li
id="item_'.$page->ID.'"><span>'.apply_filters( 'the_title',
$page->post_title, get_post_meta($post->ID,'item_',TRUE),
$get_post_meta[0],
$current_customfield = $page->$customfield ) . ' - ' .$current_customfield.
but the "current_sutomfield" displays as an array (ie; just "ARRAY"). So I
changed it to the following (added print_r):
$output .= $indent . '<li
id="item_'.$page->ID.'"><span>'.apply_filters( 'the_title',
$page->post_title, get_post_meta($post->ID,'item_',TRUE),
$get_post_meta[0],
$current_customfield = $page->$customfield ) . ' - '
.print_r($current_customfield).
but this outputs the whole post metadata (including "Array =>") so I
stopped going down that route.
I can see the author of the plugin has just made "item_" serialised. What
would be the best way to display my $customfield serialised? I know I'm
missing something really obvious but it's been racking my brains as to why
I can't get a simple line to output.
Thanks.

No comments:

Post a Comment