58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
Enhances the post management for 'sp_event' custom post type by adding custom
|
|
filters for event status
|
|
*/
|
|
|
|
// Add the custom filter dropdown
|
|
function sp_status_filter_dropdown()
|
|
{
|
|
$current_screen = get_current_screen();
|
|
|
|
if ($current_screen->id == "edit-sp_event") {
|
|
$selected = isset($_GET["sp_status"]) ? $_GET["sp_status"] : ""; ?>
|
|
<select name="sp_status">
|
|
<option value="" <?php selected(
|
|
"",
|
|
$selected
|
|
); ?>>All Status</option>
|
|
<option value="ok" <?php selected(
|
|
"ok",
|
|
$selected
|
|
); ?>>On Time</option>
|
|
<option value="tbd" <?php selected(
|
|
"tbd",
|
|
$selected
|
|
); ?>>TBD</option>
|
|
<option value="postponed" <?php selected(
|
|
"postponed",
|
|
$selected
|
|
); ?>>Postponed</option>
|
|
<option value="canceled" <?php selected(
|
|
"canceled",
|
|
$selected
|
|
); ?>>Canceled</option>
|
|
</select>
|
|
<?php
|
|
}
|
|
}
|
|
|
|
add_action("restrict_manage_posts", "sp_status_filter_dropdown");
|
|
|
|
// Modify the query based on the selected filter
|
|
function sp_status_filter_query($query)
|
|
{
|
|
global $pagenow;
|
|
|
|
if ($pagenow == "edit.php" && isset($_GET["sp_status"]) && $_GET["sp_status"] != '' ) {
|
|
$query->set("meta_query", [[
|
|
"key" => "sp_status",
|
|
"value" => $_GET["sp_status"],
|
|
"compare" => "=",
|
|
]]
|
|
);
|
|
}
|
|
}
|
|
|
|
add_action("pre_get_posts", "sp_status_filter_query");
|