0

I try to make a plugin with a widget where I can mark / check posts, maybe old post I want to bring back to life. I want to add a checkbox in the field before the title, like I try to show in the example below.

And then, If I check the checkbox for a post, the post will show up in a widget at the front side of my site. Somethink like "Did you see this ?" or "Did you remember this ?" With the post title, featured image and a link to the post.

I find a lot of plugins that users can review the posts, and then I can show the post with most reviews / stars.

That is not what I want... I want the admin / editor etc. to mark / check post that they think the viewers / users want to see again.

Maybe a carusell that shows the 3-5 posts that admin checked, example 20 seconds each. But that could be in another version.

First of all I need to find a way to make checkbox in every posts in the post list, and let the widget in front side show the post I marked.

Somebody to understand what I need and how to make it ?

enter image description here

2
  • if the goal is to select a handful of posts to appear in a carousel, that can be done relatively easily, but the checkbox requirement makes your question much harder to answer, and will take much longer for someone to write up, with more code. You could eliminate that by using a hidden category called recommended or a private non-public custom taxonomy and term, this would be significantly easier and faster to implement, and may even be possible without writing any code using the blocks that are bundled with WordPress
    – Tom J Nowell
    Mar 5, 2022 at 1:56
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Mar 9, 2022 at 21:50

1 Answer 1

0

To get you started:

<?php

/*
Plugin Name: The Checkbox Plugin
Plugin URI:  https://www.yourawesomedomain.de/plugins/
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: https://www.bjovaar.de/disclaimer
Text Domain: bjovaar
Domain Path: /languages
*/

if(!defined('ABSPATH')) {
    exit('No access');
}
// This path variable can be used for the textdomain setup, ignore if not needed
$dir = plugin_dir_path(__FILE__);


add_action('manage_post_posts_custom_column', function($column_key, $post_id) {
// $checked_post should contain your result from your database
// which I didn't show to save
$checked_post = get_post_meta($post_id, 'checked_post', true);
?>
<input type="checkbox" value="true" checked>
<?php
}, 10, 2);
// Add title to head and bottom of column
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_action "manage_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..

2
  • Note that a taxonomy would be significantly faster than a post meta for this when the widget is implemented. Post meta is for information where you already know which post it is, it's not for filtering/searching/grouping, that's what taxonomies were added for and why tags/categories are not stored as post meta
    – Tom J Nowell
    Mar 5, 2022 at 1:53
  • Yes, I agree. This code was just a shot Mar 5, 2022 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.