gpt4 book ai didi

php - 在 wordpress 中显示同一帖子 ID 的所有帖子元键和元值

转载 作者:IT王子 更新时间:2023-10-28 23:49:17 26 4
gpt4 key购买 nike

我正在尝试显示帖子元值和帖子元键,如果只显示一个值,我可以使用简单的函数 get_post_meta() 但我现在需要的是发布所有具有相同 post_id 的帖子元数据.我尝试使用 foreach 循环但没有显示。你能检查我的代码吗?

function wpt_calendar_display()
{
global $post;

$columns = array(
'date_event' => 'Date',
'name_event' => 'Event'
);
register_column_headers('list-header_events', $columns);

$event_name = get_post_meta( $post->ID, '_event_name' );
// $event_date = get_post_meta( $post->ID, '_event_date', false );

$return .= "<table class=\"widefat\">";
$return .= "<tr>";
$return .= print_column_headers('list-header_events');
$return .= "</tr>";
$return .= "<tr>";

if (!empty($event_name))
foreach($event_name as $e_name)
{
$return .= "<td>";
$return .= $e_name;
$return .="</td>";

}

$return .= "<td>";

$return .= "</td>";
$return .= "</tr>";
$return .= "</table>";
return $return;
}

最佳答案

Default Usage

Get the meta for all keys:

<?php $meta = get_post_meta($post_id); ?>

Get the meta for a single key:

<?php $key_1_values = get_post_meta( 76, 'key_1' ); ?>

例如:

$myvals = get_post_meta($post_id);

foreach($myvals as $key=>$val)
{
echo $key . ' : ' . $val[0] . '<br/>';
}

Note: some unwanted meta keys starting with "underscore(_)" will also come, so you will need to filter them out.

引用:See Codex

关于php - 在 wordpress 中显示同一帖子 ID 的所有帖子元键和元值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22216276/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com