我有一篇带有操作的自定义帖子,我喜欢只显示我单击此操作按钮时的内容。
这是我单击自定义按钮操作时注册的操作:
add_action(\'admin_init\', \'houzez_fill_listing\');
function houzez_fill_listing() {
global $post;
if(!empty($_REQUEST[\'action\'])) {
if($_REQUEST[\'action\'] == \'confirm_listing\') {
$post_id = absint($_GET[\'fill_building\']);
$listing_data = array(
\'ID\' => $post_id,
\'post_status\' => \'occupied\'
);
wp_update_post($listing_data);
update_post_meta($post_id, \'fave_property_status_building\', \'2\');
update_post_meta($post_id, \'fave_property_availability_start\', $_GET[\'start_date\']);
update_post_meta($post_id, \'fave_property_availability_end\', $_GET[\'end_date\']);
$author_id = get_post_field (\'post_author\', $post_id);
$user = get_user_by(\'id\', $author_id );
$user_email = $user->user_email;
$args = array(
\'listing_title\' => get_the_title($post_id),
\'listing_url\' => get_permalink($post_id)
);
houzez_email_type( $user_email,\'listing_expired\', $args );
wp_redirect(remove_query_arg(\'fill_listing\', add_query_arg(\'fill_listing\', $post_id, admin_url(\'edit.php?post_type=property\'))));
}
} else {
if(!empty($_REQUEST[\'fill_listing\'])) {
?>
<div class="wrap">
<h2>Confirmación para ocupar este inmueble</h2>
<form method="POST" action="<?=admin_url( \'admin.php\' )?>">
<input type="hidden" name="action" value="confirm_listing" />
<input type="hidden" name="building_id" value="\'.$_REQUEST[\'fill_listing\'].\'" />
<p>Nota: esta acción solo puede ser aplicada para ofertas que se encuentran con la condición de alquiler y alquiler temporario.</p>
<p>Elija la fecha inicial y final para confirmar la ocupación del inmueble.</p>
<div>\';
<p>Fecha inicio: <input type="text" name="start_date" id="start_date" /></p>
<p>Fecha fin: <input type="text" name="end_date" id="start_date" /></p>
</div>\';
<?=submit_button(\'Confirmar acción\').\' \'.submit_button(\'Cancelar\',\'secondary\',\'\',\'\',\'onClick="location.href=\\\'\'.wp_get_referer().\'\\\'"\');?>
</form>
</div>
<?
return false;
} else {
}
}
}
单击后,我显示如图所示:
图像链接:https://i.stack.imgur.com/3rAw6.jpg
我要做什么才能只显示内容?
谢谢
SO网友:mmm
要使用自己的内容创建页面,可以执行以下操作:
add_action("admin_menu", function () {
$post_type = get_post_type_object("property");
add_submenu_page(
" "
, "Page title"
, ""
, $post_type->cap->edit_posts
, "property__validationForm"
, function () {
do_action("property/validationForm");
}
);
});
add_action("property/validationForm", function () {
?>
<pre><?php var_dump($_GET);?></pre>
form
<?php
});
要创建指向此页面的URL,请使用以下代码:
$url = admin_url("admin.php");
$url = add_query_arg([
"page" => "property__validationForm",
"property_ID" => $property->ID,
], $url);
有关函数的更多信息
add_submenu_page
, 您可以查看法典:
https://developer.wordpress.org/reference/functions/add_submenu_page/