Add checkbox in admin post list – show checked post in widget


To get you started:


Plugin Name: The Checkbox Plugin
Plugin URI:
Description: A plugin with a checkbox to mark posts.
Version:     0.0.1
Author:      bjovaar
Author URI:  https://www.bjovaar.maybe/
License:     GPL2
License URI:
Text Domain: bjovaar
Domain Path: /languages

if(!defined('ABSPATH')) {
    exit('No access');

$dir = plugin_dir_path(__FILE__);

add_action('manage_post_posts_custom_column', function($column_key, $post_id) {

$checked_post = get_post_meta($post_id, 'checked_post', true);
<input type="checkbox" value="true" checked>
}, 10, 2);

add_filter('manage_post_posts_columns', function($columns) {
    return array_merge($columns, ['verified' => __('Marked posts', 'bjovaar')]);

The code above will create a plugin and add a checkbox to your admin dashboard in the posts list. The first add_actionmanage_post_posts_custom_colum” will call a function and create the new column. Please read under “more information” for further details of this hook. This column can also be rearranged via array sorting (depending on where you want it).

Now, at this point the following question should come up, while developing this thing (from my perspective).

Which hook do you want to use on the overview to save your checked input field since there is no “save_post” hook on this page.

The only solution from what I can think of right now would be to register a rest endpoint, and trigger an ajax request.

This is not a full answer but should show you the path to go..

bjovaar 2 years 2022-03-04T19:07:30-05:00 0 Answers 0 views 0

Leave an answer