admin管理员组文章数量:1023827
I'm wondering why WordPress doesn't list PHP array()
and any serialized data in Custom Fields in Admin Panel (for Pages, Posts etc.)? Only Custom Fields containing strings and numbers show up and can be edited by user manually.
Edit: Why aren't post meta values displayed if they are stored as a non-string value, meaning, stored as either arrays or a serialized value ?
Example: If a post has a meta key 'custom-meta' with a string value as 'yes', it is displayed in the meta box, but if it has an array value like array('value' => 'yes')
, it is not displayed in the meta box.
Can I enable this?
I'm wondering why WordPress doesn't list PHP array()
and any serialized data in Custom Fields in Admin Panel (for Pages, Posts etc.)? Only Custom Fields containing strings and numbers show up and can be edited by user manually.
Edit: Why aren't post meta values displayed if they are stored as a non-string value, meaning, stored as either arrays or a serialized value ?
Example: If a post has a meta key 'custom-meta' with a string value as 'yes', it is displayed in the meta box, but if it has an array value like array('value' => 'yes')
, it is not displayed in the meta box.
Can I enable this?
Share Improve this question edited Oct 19, 2012 at 16:47 Adam 16.5k1 gold badge45 silver badges62 bronze badges asked Oct 19, 2012 at 15:27 PaulPaul 1171 silver badge5 bronze badges 4- What admin panel are you talking about? Please add a screen hot. – fuxia ♦ Commented Oct 19, 2012 at 15:53
- 1 Custom Fields are available only in 1 place - in post/page editing screen. – Paul Commented Oct 19, 2012 at 16:05
- I have rephrased the question, hope it's a bit more clear now! – Rutwick Gangurde Commented Oct 19, 2012 at 16:11
- Thanks for re-writing this with examples :) But I'm still looking for some clarification. Why arrays don't show up? – Paul Commented Oct 20, 2012 at 16:07
3 Answers
Reset to default 4There is no filter to change that behavior, you would have to replace the entire metabox.
On the other hand: I think there is no really simple way to show and to save those arrays.
Example for a fictive meta key 'foo'
:
array (
0 => 2,
'hello' => array (
0 => 2,
'hello' => 'world'
)
)
Creating a default interface for such an array would be very hard. This metabox is for simple fields, it should be easy to use. And you cannot just present the serialized string: editing that would probably break it. So I think it is a compromise. Better than nothing, but not perfect.
I think you can use serialize()
Example:
$value = array('value' => 'yes');
$new_value = serialize($value);
add_post_meta($post_id,'meta_key',$new_value);
Then, you can see the metabox in admin panel.
For those landing here, you could always just create a custom page template on a private page and then just throw something like this on the template page file:
/*Template Name: Test Post Meta */
$thisPostMeta = get_post_meta($yourPostId, 'meta_key');
//Check for type of value
if (is_array($thisPostMeta)) {
print_r($thisPostMeta);
} else {
echo $thisPostMeta;
}
Note: untested.
I'm wondering why WordPress doesn't list PHP array()
and any serialized data in Custom Fields in Admin Panel (for Pages, Posts etc.)? Only Custom Fields containing strings and numbers show up and can be edited by user manually.
Edit: Why aren't post meta values displayed if they are stored as a non-string value, meaning, stored as either arrays or a serialized value ?
Example: If a post has a meta key 'custom-meta' with a string value as 'yes', it is displayed in the meta box, but if it has an array value like array('value' => 'yes')
, it is not displayed in the meta box.
Can I enable this?
I'm wondering why WordPress doesn't list PHP array()
and any serialized data in Custom Fields in Admin Panel (for Pages, Posts etc.)? Only Custom Fields containing strings and numbers show up and can be edited by user manually.
Edit: Why aren't post meta values displayed if they are stored as a non-string value, meaning, stored as either arrays or a serialized value ?
Example: If a post has a meta key 'custom-meta' with a string value as 'yes', it is displayed in the meta box, but if it has an array value like array('value' => 'yes')
, it is not displayed in the meta box.
Can I enable this?
Share Improve this question edited Oct 19, 2012 at 16:47 Adam 16.5k1 gold badge45 silver badges62 bronze badges asked Oct 19, 2012 at 15:27 PaulPaul 1171 silver badge5 bronze badges 4- What admin panel are you talking about? Please add a screen hot. – fuxia ♦ Commented Oct 19, 2012 at 15:53
- 1 Custom Fields are available only in 1 place - in post/page editing screen. – Paul Commented Oct 19, 2012 at 16:05
- I have rephrased the question, hope it's a bit more clear now! – Rutwick Gangurde Commented Oct 19, 2012 at 16:11
- Thanks for re-writing this with examples :) But I'm still looking for some clarification. Why arrays don't show up? – Paul Commented Oct 20, 2012 at 16:07
3 Answers
Reset to default 4There is no filter to change that behavior, you would have to replace the entire metabox.
On the other hand: I think there is no really simple way to show and to save those arrays.
Example for a fictive meta key 'foo'
:
array (
0 => 2,
'hello' => array (
0 => 2,
'hello' => 'world'
)
)
Creating a default interface for such an array would be very hard. This metabox is for simple fields, it should be easy to use. And you cannot just present the serialized string: editing that would probably break it. So I think it is a compromise. Better than nothing, but not perfect.
I think you can use serialize()
Example:
$value = array('value' => 'yes');
$new_value = serialize($value);
add_post_meta($post_id,'meta_key',$new_value);
Then, you can see the metabox in admin panel.
For those landing here, you could always just create a custom page template on a private page and then just throw something like this on the template page file:
/*Template Name: Test Post Meta */
$thisPostMeta = get_post_meta($yourPostId, 'meta_key');
//Check for type of value
if (is_array($thisPostMeta)) {
print_r($thisPostMeta);
} else {
echo $thisPostMeta;
}
Note: untested.
本文标签: functionsWP doesn39t show Array Custom Fields
版权声明:本文标题:functions - WP doesn't show Array Custom Fields? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745587350a2157678.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论