wordpress プラグイン 自作
■参考
https://gist.github.com/ericjuden/5136638
https://github.com/souparno/wp-plugin-CRUD
・edit-form-advanced.php
<?php if(isset($_GET["post_type"])): ?>
<?php if( $_GET["post_type"] == "tour-schedule"): ?>
<p id="shop-lists">▼ 出張先一覧</p>
<?php
global $wpdb;
$query = "SELECT * FROM tours;";
$rows = $wpdb->get_results($query);
?>
<div id="lists">
<?php foreach($rows as $row) : ?>
<div class="shop-data">
<span class="shop-name"><?= $row->name ?></span>
<span class="postal"><?= $row->postal ?></span>
<span class="address"><?= $row->address ?></span>
<span class="tel"><?= $row->tel ?></span>
</div>
<?php endforeach; ?>
</div>
<style>
#lists {
background-color: #fff;
padding:.5em;
}
.shop-data {
cursor: pointer;
margin-bottom:4px;
}
.shop-data:hover {
background-color: #ff0;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>
$(function(){
$('#lists').hide();
$('#shop-lists').click(function(){$(this).next().slideToggle(50);});
$('.shop-data').click(function(){
$('#title-prompt-text').text('');
$('input[name=post_title]').val($(this).children('.shop-name').text());
$('#acf-field-place').val('「' + $(this).children('.shop-name').text() + '」' + ' 〒' + $(this).children('.postal').text() + ' ' + $(this).children('.address').text());
$('#acf-field-book').val('「' + $(this).children('.shop-name').text() + '」' + ' ' + $(this).children('.tel').text());
$(this).parent().toggle();
});
});
</script>
<?php endif; ?>
<?php endif; ?>
・function.php
function change_default_title( $title ) {
$screen = get_current_screen();
if ( $screen -> post_type == 'tour-schedule' ) {
$title = '店舗名を入力 (例)店';
}
return $title;
}
add_filter('enter_title_here', 'change_default_title');