Answer the question
In order to leave comments, you need to log in
WordPress plugin with CUSTOM POST TYPE. Does it make sense?
Alas, a complete amateur in this area. In this regard, I ask for advice from more sophisticated colleagues)) I
usually create plugins according to the following scheme. I am writing the plugin file itself, where I attach the template connection, the necessary scripts and styles to the shortcode. If any parameters are needed, I pass them through a short code.
affairs. it's all like this:
function load_table_manager()
{
wp_enqueue_style('table_manager_css',"//handsontable.com/dist/handsontable.full.css");
ob_start();
include dirname(__FILE__) . '/template.php'; // здесь вся нужная разметка
$result = ob_get_contents();
ob_end_clean();
table_manager_scripts(); // функция для подгрузки JS через wp_enqueue_script
return $result;
}
add_shortcode('table_manager','load_table_manager');
[table_manager table_name ='my_best_table']
and that's it! Why is CUSTOM POST TYPE here? What is the profit besides the minus in the form of a loss of plugin autonomy? function get_custom_post_type_template($single_template) {
global $post;
if ($post->post_type == 'data_table') {
$single_template = dirname( __FILE__ ) . '/template.php';
}
return $single_template;
}
add_filter( 'single_template', 'get_custom_post_type_template' );
Answer the question
In order to leave comments, you need to log in
Regarding the need to go beyond the standalone plugin - this is not necessary, CPT can be non-public and available only in the admin + through your plugin in your template, without routing, etc.
As for everything else - yes, you are doing it very inefficiently, and, I would even say crookedly. No offense. Now I’m already lying down to rest, tomorrow I’ll try to find a minute and write in detail what is wrong and where to dig (I will update this answer).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question