if (window.location.href.indexOf("post.php?post=") > -1 && window.location.href.indexOf("&action=edit") > -1){
var estate_id = location.href.substr(location.href.indexOf('post=')).split('&')[0].split('=')[1];
console.log('id = '+estate_id);
jQuery.ajax({
type:"POST",
url: ajaxurl,
dataType: 'json',
data: { action: "get_estate_object_data", estate_id: estate_id},
beforeSend: function(){console.log('Отправляем');},
success: function(estate_object_data) {
console.log(estate_object_data);
jQuery.each( estate_object_data, function( index, Value ) {
jQuery('input:text ' + '[needed=true],' + '#'+index).val(Value);
jQuery('select ' + '[needed=true],' + '#'+index).val(Value).attr('selected','selected');
if(Value=="true"){
jQuery('input:checkbox ' + '[needed=true],' + '#'+index).attr("checked", "checked");console.log(index);
}
//jQuery('button ' + '[needed=true],'+ '#'+index).attr('aria-pressed', Value);
});
//$('input, select, textarea, ' + 'a[data-toggle="foo"], p[target="bar"],' + '#hello')
} // success function
});
}
estate_service-fridge:"true"
estate_service-internet:"false"
estate_service-tv:"true"
estate_service-washing_machine:"false"
estate_sevice-phone:"false"
<div class="form-check form-check-inline"><label class="form-check-label" for="estate_loggia"><input class="form-check-input" type="checkbox" needed="true" id="estate_loggia" value="Лоджия"> Лоджия</label></div>
jQuery('#add_new_estate_object').on('click', function(){
estate_data= [];
jQuery('input[needed="true"]').each(function(){
var id = jQuery(this).attr('id'); var type = jQuery(this).attr('type'); var val = jQuery(this).val();
if(type == 'checkbox'){ if( jQuery(this).attr("checked") == 'checked'){ estate_data[id] = "true" } else { estate_data[id] = "false" } }
if(type == 'text'){ estate_data[id] = val; }
});
jQuery('select[needed="true"]').each(function(){
var id = jQuery(this).attr('id');
estate_data[id] = jQuery(this).find('option:selected').val();
});
jQuery('textarea[needed="true"]').each(function(){
estate_data[jQuery(this).attr("id")] = jQuery(this).val() ;
});
/*jQuery('button[needed="true"]').each(function(){
// Собрать данные с кнопкок
});*/
});
<?php
/*
Plugin Name: Custom Searcher
Plugin URI: https://toster.ru/q/562855?e=6881848#answer_item_1274474
Description: Плагин поиска записей по дате с формой
Version: 1.0
Author: @san_jorich
Author URI: https://toster.ru/user/san_jorich
License: GPL2
*/
wp_register_script('searcher', plugins_url('searcher.js', __FILE__)); wp_enqueue_script('searcher');
wp_localize_script( 'searcher', 'ajaxurl', admin_url( 'admin-ajax.php' ) );
add_action( 'wp_ajax_searcher','searcher' ); add_action( 'wp_ajax_nopriv_searcher','searcher' );
function searcher($search_date){
if( !isset($_POST['search_date']) ){ $msg = "Упс.. Что-то пошло не так, поиск не выполнен.."); } else {
$search_results=();
$date = $_POST['search_date'];
$orderdate = explode('-', $orderdate); $day = $orderdate[2]; $month = $orderdate[1]; $year = $orderdate[0]; // yyyy-mm-dd
$search_params = array( 'post_type' => 'post', 'orderby' => 'date', 'order' => 'DESC', 'suppress_filters' => true, 'date_query' => array( array( 'year' => $year, 'month' => $month, 'day' => $day ) ) );
$query = new WP_Query($search_params);
while($query->have_posts()) { $query->the_post(); array_push('<a href="' . get_permalink() . '">' . get_the_title() . '</a>',$search_results); }
wp_reset_postdata(); $msg="Записи, найденные по запросу";
}
$report = ['msg'=> $msg,'posts'=>$search_results];
wp_send_json($report); die();
}
/* ВНИМАНИЕ: Код написан в качестве примера, требуются правки и доработки */
?>
/* Файл searcher.js. Расположение в корне плагина. Можно было бы зацепить к футеру, но это фу)) */
jQuery(document).ready(function() {
jQuery( '#search_it').on('click',function(){
var search_date = jQuery('#search_date').val();
jQuery.ajax({ type: "POST", url: ajaxurl, dataType: "json", data: { action: "searcher", search_date : search_date}, success: function(report) { jQuery("#custom_search_result").html('<h2>'+report.msg+'</h2><br>'+report.posts+'<hr>'); },
});
});
Почитайте про функции register_post_type( 'type_name, $args ); и register_taxonomy( 'custonomy_name', array( 'type_name' ), $args );
Вроде у WP были готовые решения в виде плагинов, помогающие реализовать все это, но лучше руками.
Должны