WordPress就是这样保存我的CPT元数据的:
array(8) {
["product_id"]=> array(1) { [0]=> string(10) "abcdefg987" }
["end_date"]=> array(1) { [0]=> string(10) "02-02-2015" }
}
但我希望它是这样的:
array(8) {
["product_id"]=> "abcdefg987" ,
["end_date"]=> "02-02-2015"
}
那么,有可能吗?
这是我的一些代码:
to save:
update_post_meta($post_id, "end_date", $_POST["end_date"]);
The meta box:
global $post;
$custom = get_post_custom($post->ID);
$end_date = $custom["end_date"][0]; // <- this was an old hack to this problem
<p><label>End Date:</label><br />
<input name="end_date" value="<?php echo $end_date; ?>"></input></p>
<小时>
What I really want to do ?我需要的是获得“end\\u date”大于今天的帖子(自定义)。因此,我有一个meta\\u查询,但不起作用,因为还会显示带有“end\\u date”的帖子<;今天,我想是因为它在数组中得到了它的值,而不仅仅是值,下面是代码:
$args = array(
\'post_type\' => \'myEventCPT\',
\'meta_query\' => array(
array( \'meta_key\' => \'end_date\',
\'value\' => date("m-d-Y"), // Set today\'s date
\'compare\' => \'>=\',
//\'type\' => \'DATE\'
)
)
);
$my_event_post = get_posts( $args );
SO网友:Francisco Corrales Morales
好的,我解决了(在Reddit和StackExchange的所有人的帮助下),我有几个问题
这是我的工作代码:
$args = array(
\'numberposts\' => 1,
\'post_type\' => \'my-cpt\',
\'order\' => \'ASC\' ,
\'meta_query\' => array(
\'relation\' => \'AND\',
array( \'key\' => \'end_date\',
\'value\' => date("Y-m-d"), //today
\'compare\' => \'>=\',
\'type\' => \'DATE\'
),
array( \'key\' => \'product_id\',
\'value\' => $product[\'id\'],
\'compare\' => \'=\',
\'type\' => \'CHAR\'
),
),
);