Support Forum
Hi all,
I am a new client of Meta Box AIO. I don't have much experience with WordPress plugin development, but I hope I can learn to make nice plugins for my clients.
It was easy to make my first Custom Post Type and Custom fields.
I didn't see it in Meta Box but it would be really nice if I can make "add_help_tab" with my custom post types.
And is it possible with Meta Box to create links with search queries for post types?
I will give an example code below. It would be very nice if it would be possible without custom PHP code.
<?php
/**
* Plugin Name: DEMO
* Author: Peter
*/
add_action( 'init', 'your_prefix_register_post_type' );
function your_prefix_register_post_type() {
$labels = [
'name' => esc_html__( 'facturen', 'your-textdomain' ),
'singular_name' => esc_html__( 'factuur', 'your-textdomain' ),
'add_new' => esc_html__( 'Add New', 'your-textdomain' ),
'add_new_item' => esc_html__( 'Add New factuur', 'your-textdomain' ),
'edit_item' => esc_html__( 'Edit factuur', 'your-textdomain' ),
'new_item' => esc_html__( 'New factuur', 'your-textdomain' ),
'view_item' => esc_html__( 'View factuur', 'your-textdomain' ),
'view_items' => esc_html__( 'View facturen', 'your-textdomain' ),
'search_items' => esc_html__( 'Search facturen', 'your-textdomain' ),
'not_found' => esc_html__( 'No facturen found.', 'your-textdomain' ),
'not_found_in_trash' => esc_html__( 'No facturen found in Trash.', 'your-textdomain' ),
'parent_item_colon' => esc_html__( 'Parent factuur:', 'your-textdomain' ),
'all_items' => esc_html__( 'All facturen', 'your-textdomain' ),
'archives' => esc_html__( 'Factuur Archives', 'your-textdomain' ),
'attributes' => esc_html__( 'Factuur Attributes', 'your-textdomain' ),
'insert_into_item' => esc_html__( 'Insert into factuur', 'your-textdomain' ),
'uploaded_to_this_item' => esc_html__( 'Uploaded to this factuur', 'your-textdomain' ),
'featured_image' => esc_html__( 'Featured image', 'your-textdomain' ),
'set_featured_image' => esc_html__( 'Set featured image', 'your-textdomain' ),
'remove_featured_image' => esc_html__( 'Remove featured image', 'your-textdomain' ),
'use_featured_image' => esc_html__( 'Use as featured image', 'your-textdomain' ),
'menu_name' => esc_html__( 'Facturen', 'your-textdomain' ),
'filter_items_list' => esc_html__( 'Filter facturen list', 'your-textdomain' ),
'filter_by_date' => esc_html__( '', 'your-textdomain' ),
'items_list_navigation' => esc_html__( 'Facturen list navigation', 'your-textdomain' ),
'items_list' => esc_html__( 'Facturen list', 'your-textdomain' ),
'item_published' => esc_html__( 'Factuur published.', 'your-textdomain' ),
'item_published_privately' => esc_html__( 'Factuur published privately.', 'your-textdomain' ),
'item_reverted_to_draft' => esc_html__( 'Factuur reverted to draft.', 'your-textdomain' ),
'item_scheduled' => esc_html__( 'Factuur scheduled.', 'your-textdomain' ),
'item_updated' => esc_html__( 'Factuur updated.', 'your-textdomain' ),
];
$args = [
'label' => esc_html__( 'Facturen', 'your-textdomain' ),
'labels' => $labels,
'description' => '',
'public' => false,
'hierarchical' => false,
'exclude_from_search' => true,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
'show_in_rest' => true,
'query_var' => false,
'can_export' => true,
'delete_with_user' => true,
'has_archive' => false,
'rest_base' => '',
'show_in_menu' => true,
'menu_position' => '',
'menu_icon' => 'dashicons-admin-generic',
'capability_type' => 'post',
'supports' => false,
'taxonomies' => [],
'rewrite' => [
'with_front' => false,
],
];
register_post_type( 'factuur', $args );
}
function add_custom_help_tab() {
$screen = get_current_screen();
error_log('Huidig scherm ID: ' . $screen->id);
// Controleer of je op de juiste custom post type pagina bent, in dit geval 'factuur'
if ('edit-factuur' == $screen->id ) {
// Eerste hulptab
$screen->add_help_tab(array(
'id' => 'jouw_unieke_id_factuur',
'title' => 'Hulp voor Facturen',
'content' => '<p>Hier is wat nuttige informatie over facturen...</p>',
));
// Tweede hulptab
$screen->add_help_tab(array(
'id' => 'jouw_tweede_unieke_id',
'title' => 'Extra Hulp Onderwerp',
'content' => '<p>Extra informatie over een ander onderwerp...</p>',
));
// Voeg een sidebar toe
$screen->set_help_sidebar(
'<p><strong>Extra Hulp Titel</strong></p>' .
'<p>Dit is wat extra hulptekst voor de sidebar.</p>'
);
}
}
add_action('admin_head', 'add_custom_help_tab', 20);
add_filter( 'views_edit-factuur', 'add_yearly_filters_to_facturen' );
function add_yearly_filters_to_facturen( $views ) {
$years = array('2023', '2024');
foreach ($years as $year) {
$url = admin_url('edit.php?post_type=factuur&year=' . $year);
$views[$year] = "<a href='$url'>$year</a>";
}
return $views;
}
add_action('pre_get_posts', 'filter_facturen_by_year');
function filter_facturen_by_year($query) {
if (!is_admin() || !$query->is_main_query()) {
return;
}
if (!empty($_GET['year']) && 'factuur' == $query->get('post_type')) {
$query->set('year', intval($_GET['year']));
}
}
making pousible to turn off the date column and actions will also be great to have a online line height row in wp-list-table ...much cleaner!!
function remove_date_column($columns) {
unset($columns['date']);
return $columns;
}
add_filter('manage_potential_posts_columns', 'remove_date_column', 10, 1);
function remove_all_relatie_post_row_actions($actions, $post) {
if ('potential' === $post->post_type) {
return array(); // Verwijdert alle row-actions
}
return $actions;
}
Hello there,
Meta Box doesn't support an option to create the help tab. It just passes the arguments from UI to the function register_post_type()
of WordPress to create the post type. You can use the custom code to create help tabs on your end.