供日后参考。我通过更新保存例程将每个字段保存到自己的键来解决问题。由于每个字段都保存到其相应的键中,因此这确实可以更好地工作,从而可以更好地从WP\\U查询中检索
/* check if this is an autosave and if YES then do nothing */
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
return;
/* Verify the nonce field of the meta box */
if ( !wp_verify_nonce( $_POST[\'propdp_details_noncename\'], plugin_basename( __FILE__ ) ) )
return;
/* Check if the user can edit the post and if NOT the return and do nothing */
if ( !current_user_can( \'edit_post\', $post_id ) )
return;
/* start my array object to hold all my data to save */
$detailsData = array();
/* run through $_POST to check for all matching keys and values */
foreach($_POST as $key => $data)
{
if($key == \'propdp_details_noncename\')
continue;
if(preg_match(\'/^propdp_details/i\', $key))
{
$detailsData [$key] = $data;
}
}
/* loop through all gathered keys and values to add, update and delete meta */
foreach($detailsData as $meta_key => $new_value)
{
//get old value of meta key
$curr_value = get_post_meta( $post_id, $meta_key, true );
//check if old value exists and add if OLD NOT EXIST
if($new_value && \'\' == $curr_value)
{
add_post_meta( $post_id, $meta_key, $new_value, true );
}
//check if old value == new value and update if NEW NOT EQUAL
elseif($new_value && $new_value != $curr_value)
{
update_post_meta( $post_id, $meta_key, $new_value);
}
//check if new value exists and delete if NEW NOT EXIST
elseif(\'\' == $new_value && $curr_value)
{
delete_post_meta( $post_id, $meta_key, $curr_value);
}
}
这允许我像这样使用WP\\u Query args数组
$myQueryArr = array(
\'post_type\' => array(\'custom\', \'post\', \'types\'),
\'post_status\' => \'publish\',
\'meta_query\' => array(
array(
\'key\'=>\'propdp_details_listing_agent\',
\'value\'=>$currentID
)
)
);