我有一个自定义查询,其中包含一些重复选项值。我有三个选项卡可以查询发布、草稿和全部。在“已发布”选项卡下保存值时,将删除“草稿”下的所有值,反之亦然。我需要能够保存当前输入的值,并保留其他值。下面是我当前的代码。有什么建议吗?
<?php
add_action(\'admin_menu\', \'properties_status_menu\');
function properties_status_menu() {
add_submenu_page( \'edit.php?post_type=properties\', \'Status\', \'Status\', \'manage_options\', \'properties-status\', \'properties_status_page_handler\');
}
function properties_status_page_handler(){
global $post, $current, $searchOwner;
function property_status_tabs( $current = \'active\') {
$tabs = array( \'active\' => \'Active\', \'inactive\' => \'Inactive\', \'all\' => \'All\' );
//echo \'<div id="icon-themes" class="icon32"><br></div>\';
echo \'<h2 class="nav-tab-wrapper">\';
foreach( $tabs as $tab => $name ){
$class = ( $tab == $current ) ? \'nav-tab-active\' : \'\';
echo \'<a class="nav-tab \' . $class . \'" href="/wp-admin/edit.php?post_type=properties&page=properties-status&tab=\' . $tab . \'">\' . $name . \'</a>\';
}
echo \'</h2>\';
}
$tab = ( ! empty( $_GET[\'tab\'] ) ) ? esc_attr( $_GET[\'tab\'] ) : \'active\';
property_status_tabs( $tab );
if(isset($_POST[\'searchProp\'])){
$propTitle = $_POST[\'searchProp\'];
}else {
$propTitle = \'\';
}
if(isset($_POST[\'searchOwner\'])){
$searchOwner = $_POST[\'searchOwner\'];
}else {
$searchOwner = \'\';
}
remove_all_filters(\'posts_orderby\');
if($tab == \'active\' && isset($_POST[\'searchOwner\'])){
$args = array(
\'post_type\' => \'properties\',
\'posts_per_page\' => -1,
\'order\' => \'DESC\',
\'orderby\' => \'title\',
\'post_status\' => \'publish\',
\'s\' => $propTitle,
\'tax_query\' => array( // NOTE: array of arrays!
array(
\'taxonomy\' => \'owners\',
\'field\' => \'slug\',
\'terms\' => $searchOwner,
\'operartor\' => \'IN\'
)
)
);
}else if($tab == \'active\'){
$args = array(
\'post_type\' => \'properties\',
\'posts_per_page\' => -1,
\'orderby\' => \'title\',
\'order\' => \'DESC\',
\'post_status\' => \'publish\',
\'s\' => $propTitle,
);
}
//Inactive search by address
if($tab == \'inactive\' && isset($_POST[\'searchProp\'])){
$args = array(
\'post_type\' => \'properties\',
\'posts_per_page\' => -1,
\'orderby\' => \'title\',
\'order\' => \'DESC\',
\'post_status\' => \'draft\',
\'s\' => $propTitle,
);
}
if($tab == \'inactive\' && isset($_POST[\'searchOwner\'])){
$args = array(
\'post_type\' => \'properties\',
\'posts_per_page\' => -1,
\'orderby\' => \'title\',
\'order\' => \'DESC\',
\'post_status\' => \'draft\',
\'s\' => $propTitle,
\'tax_query\' => array( // NOTE: array of arrays!
array(
\'taxonomy\' => \'owners\',
\'field\' => \'slug\',
\'terms\' => $searchOwner,
\'operartor\' => \'IN\'
)
)
);
}else if($tab == \'inactive\'){
$args = array(
\'post_type\' => \'properties\',
\'posts_per_page\' => -1,
\'orderby\' => \'title\',
\'order\' => \'DESC\',
\'post_status\' => \'draft\',
\'s\' => $propTitle
);
}
if($tab == \'all\' && isset($_POST[\'searchOwner\'])){
$args = array(
\'post_type\' => \'properties\',
\'posts_per_page\' => -1,
\'orderby\' => \'title\',
\'order\' => \'DESC\',
\'post_status\' => array(
\'publish\', \'draft\'
),
\'s\' => $propTitle,
);
}else if($tab == \'all\'){
$args = array(
\'post_type\' => \'properties\',
\'posts_per_page\' => -1,
\'orderby\' => \'title\',
\'order\' => \'DESC\',
\'post_status\' => array(
\'publish\', \'draft\'
),
\'s\' => $propTitle );
}
if(isset( $_POST[\'p_status_update\'] ) ){
$renewal = $_POST[\'renewal\'];
$frent = $_POST[\'future-rent\'];
$available = $_POST[\'available\'];
$deposit = $_POST[\'deposit\'];
$lastShowing = $_POST[\'last-showing\'];
$status = $_POST[\'status\'];
$date = $_POST[\'date\'];
$initials = $_POST[\'initials\'];
$notes = $_POST[\'notes\'];
update_option(\'renewal\', $renewal);
update_option(\'future-rent\', $frent);
update_option(\'available\', $available);
update_option(\'deposit\', $deposit);
update_option(\'last-showing\', $lastShowing);
update_option(\'status\', $status);
update_option(\'date\', $date);
update_option(\'initials\', $initials);
update_option(\'notes\', $notes);
}
?>
<div class="wrap">
<h1>Status:</h1>
<style>
.widefat .room-column {
width: 3.2em;
vertical-align: top;
}
.widefat textarea {
width: 100%;
}
.button-primary {
margin: 10px 0 10px 0 !important;
}
.widefat input {
width: 95%;
}
input:disabled {
background: #FFF !important;
color: #000 !important;
}
</style>
<script>
jQuery(document).ready(function($){
$(\'select[name="searchOwner"]\').change(function(){
$(\'#searchOwners\').submit();
});
});
</script>
<form id="searchProperties" name="searchProperties" method="post" action="" style="margin: 15px 15px 15px 0; float: left;">
<label>Search By Street Address</label><div><input id="searchProp" name="searchProp" type="input" size="50" placeholder="Street address" /></div>
</form>
<form id="searchOwners" name="searchOwners" method="post" action="" style="margin: 15px 0 15px 0; float: left;">
<label>Search By Owner</label> <?php fstudio_custom_taxonomy_dropdown( \'owners\', \'date\', \'DESC\', \'\', \'searchOwner\', \'select owner\' ); ?>
</form>
<div style="clear: both;"></div>
<form action="" method="post">
<?php wp_nonce_field( \'property_status_update\', \'p_status_update\' ); ?>
<input type="submit" name="update_statuses" value="Update" class="button-primary" />
<table class="wp-list-table widefat fixed striped posts">
<thead>
<tr>
<th class="manage-column column-cb room-column">Beds</th>
<th class="manage-column column-columnname">Address</th>
<th class="manage-column column-columnname">Renewal</th>
<th class="manage-column column-columnname">Future Rent</th>
<th class="manage-column column-columnname">Availability Date</th>
<th class="manage-column column-columnname">Deposit</th>
<th class="manage-column column-columnname">Last Showing</th>
<th class="manage-column column-columnname">Status</th>
<th class="manage-column column-columnname">Date</th>
<th class="manage-column column-columnname">Initials</th>
<th class="manage-column column-columnname">Notes</th>
</tr>
</thead>
<?php
//global $post;
$count = 0;
$propQuery = new WP_Query($args);
//var_dump($propQuery->request);
while ( $propQuery->have_posts() ) : $propQuery->the_post();
$PID = $post->ID;
$count++;
$bedrooms = wp_get_post_terms($PID, \'bedrooms\', array("fields" => "all"));
foreach( $bedrooms as $room ) {
$bedSlug = $room->slug;
}
if ($bedSlug != "individual-lease") {
$bedStripped = preg_replace(\'/[^0-9]/\', \'\', $bedSlug);
}else{
$bedStripped = \'1\';
}
$unitrent = wp_get_post_terms($post->ID, \'rent\', array("fields" => "all"));
foreach( $unitrent as $rent ) {
$rentprice = $rent->name;
$rentpriceSlug = $rent->slug;
}
$dateAvailable = get_cfc_field(\'propertysettings\', \'date-available\');
?>
<tr>
<th class="room-column">
<?php echo $bedStripped; ?>
</th>
<td>
<a href="<?php echo get_edit_post_link(); ?>" target="_blank"><?php the_title(); ?></a>
</td>
<td>
<select name="renewal[<?php echo $PID; ?>]" id="renewal[<?php echo $PID; ?>]">
<option value="0" <?php if (get_option(\'renewal\')[$PID] == 0 ) echo \'selected\' ; ?>>Choose</option>
<option value="No" <?php if (get_option(\'renewal\')[$PID] == \'No\' ) echo \'selected\' ; ?>>No</option>
<option value="Yes" <?php if (get_option(\'renewal\')[$PID] == \'Yes\' ) echo \'selected\' ; ?>>Yes</option>
</select>
</td>
<td>
<!--<textarea name="future-rent[<?php //echo $PID; ?>]" id="future-rent[<?php //echo $PID; ?>]"><?php //echo get_option(\'future-rent\')[$PID]; ?></textarea>-->
<input type="text" disabled value="<?php echo $rentprice; ?>" />
</td>
<td>
<!--<textarea name="available[<?php //echo $PID; ?>]" id="available[<?php //echo $PID; ?>]"><?php //echo get_option(\'available\')[$PID]; ?></textarea>-->
<input type="text" disabled value="<?php echo $dateAvailable; ?>" />
</td>
<td>
<!--<textarea name="deposit[<?php //echo $PID; ?>]" id="deposit[<?php //echo $PID; ?>]"><?php //echo get_option(\'deposit\')[$PID]; ?></textarea>-->
<input type="text" disabled value="<?php the_cfc_field(\'leasingsettings\', \'deposit\'); ?>" />
</td>
<td>
<textarea name="last-showing[<?php echo $PID; ?>]" id="last-showing[<?php echo $PID; ?>]"><?php echo get_option(\'last-showing\')[$PID]; ?></textarea>
</td>
<td>
<select name="status[<?php echo $PID; ?>]" id="status[<?php echo $PID; ?>]">
<option value="0" <?php if (get_option(\'status\')[$PID] == 0 ) echo \'selected\' ; ?>>-</option>
<option value="nf" <?php if (get_option(\'status\')[$PID] == \'nf\' ) echo \'selected\' ; ?>>Needs Fees</option>
<option value="bgi" <?php if (get_option(\'status\')[$PID] == \'bgi\' ) echo \'selected\' ; ?>>BGI</option>
<option value="fa" <?php if (get_option(\'status\')[$PID] == \'fa\' ) echo \'selected\' ; ?>>Final Approval</option>
<option value="a" <?php if (get_option(\'status\')[$PID] == \'a\' ) echo \'selected\' ; ?>>Approved</option>
<option value="nd" <?php if (get_option(\'status\')[$PID] == \'nd\' ) echo \'selected\' ; ?>>Need Deposit</option>
<option value="dp" <?php if (get_option(\'status\')[$PID] == \'dp\' ) echo \'selected\' ; ?>>Deposit Paid</option>
<option value="ats" <?php if (get_option(\'status\')[$PID] == \'ats\' ) echo \'selected\' ; ?>>Appt to Sign</option>
<option value="rnl" <?php if (get_option(\'status\')[$PID] == \'rnl\' ) echo \'selected\' ; ?>>Renew Lease</option>
<option value="ls" <?php if (get_option(\'status\')[$PID] == \'ls\' ) echo \'selected\' ; ?>>Lease Signed</option>
</select>
<?php
if(isset( $_POST[\'p_status_update\'] ) ){
if (get_option(\'status\')[$PID] === \'bgi\' || get_option(\'status\')[$PID] === \'a\' || get_option(\'status\')[$PID] === \'nd\'){
update_post_meta( $PID, \'app-pending\', \'Yes\' );
}else if (get_option(\'status\')[$PID] != \'bgi\' || get_option(\'status\')[$PID] != \'a\' || get_option(\'status\')[$PID] != \'nd\'){
update_post_meta( $PID, \'app-pending\', \'No\' );
}
if (get_option(\'status\')[$PID] === \'dp\' && get_post_status ( $PID ) == \'publish\'){
wp_update_post(array(\'ID\' => $PID, \'post_status\' => \'draft\'));
}
}
?>
</td>
<td>
<textarea name="date[<?php echo $PID; ?>]" id="date[<?php echo $PID; ?>]"><?php echo get_option(\'date\')[$PID]; ?></textarea>
</td>
<td>
<textarea name="initials[<?php echo $PID; ?>]" id="initials[<?php echo $PID; ?>]"><?php echo get_option(\'initials\')[$PID]; ?></textarea>
</td>
<td>
<textarea name="notes[<?php echo $PID; ?>]" id="notes[<?php echo $PID; ?>]"><?php echo get_option(\'notes\')[$PID]; ?></textarea>
</td>
</tr>
<?php
endwhile; wp_reset_postdata();
echo \'<div style="float:right;">Total: \'.$count.\'</div>\';
?>
</table>
<input type="submit" id="update_statuses" name="update_statuses" value="Update" class="button-primary" />
</form>
</div>
<?php
}
?>