From 6068a14c244af181db759a51311918bfc41a7371 Mon Sep 17 00:00:00 2001 From: Eclipse Srl Date: Thu, 2 Apr 2020 10:07:43 +0200 Subject: [PATCH] added taxonomies meta box --- README.txt | 5 ++- includes/CPT/CustomPostTypes.php | 61 +++++++++++++++++++++++++++++++- includes/misc/terms.php | 23 ++++++++++++ udesly-adapter-plugin.php | 4 +-- 4 files changed, 89 insertions(+), 4 deletions(-) diff --git a/README.txt b/README.txt index 1ca425b..a09f948 100644 --- a/README.txt +++ b/README.txt @@ -4,7 +4,7 @@ Donate link: https://www.udesly.com/ Tags: webflow to wordpress, editor, page builder, layout design, udesly, webflow Requires at least: 5.0 Tested up to: 5.2.3 -Stable tag: 2.0.2 +Stable tag: 2.0.3 License: GPLv3 or later License URI: https://www.udesly.com/terms-conditions-of-use/#udesly-wordpress-plugin Requires PHP: 5.6.0 @@ -82,6 +82,9 @@ Absolutely! You can use the Udesly Adapter to create more than one website. == Changelog == += 2.0.3 = +* Added metabox to choose taxonomies inside custom post type + = 2.0.2 = * Added js support for multiple mini cart in same page diff --git a/includes/CPT/CustomPostTypes.php b/includes/CPT/CustomPostTypes.php index 86826d5..5ba17d1 100644 --- a/includes/CPT/CustomPostTypes.php +++ b/includes/CPT/CustomPostTypes.php @@ -111,7 +111,10 @@ public static function init_all_custom_post_types() ), 'rewrite' => array( 'slug' => $slug - ) + ), + 'show_ui' => true, + 'show_admin_column' => true, + 'query_var' => true, )); } } @@ -138,6 +141,8 @@ public static function taxonomy_rewrite_slug_field($args) $post_type) { + + $title = str_replace('_', ' ', $taxonomy); + $title = ucfirst($title); + add_meta_box( "taxonomy-dropdown-div--${taxonomy}", $title, [self::class, 'add_taxonomy_metabox'],$post_type ,'side','core', $taxonomy); + } + } + + public static function add_taxonomy_metabox( $post, $args ) { + $title = $args['title']; + $taxonomy = $args['args']; + //The name of the form + $name = 'tax_input[' . $taxonomy . '][]'; + $id = $taxonomy.'dropdown'; + //Get current and popular terms + $postterms = get_the_terms( $post->ID, $taxonomy ); + $current = ($postterms ? array_pop($postterms) : false); + $current = ($current ? $current->term_id : 0); + ?> + +
+ +
+ "Choose a $title", + 'show_option_none' => '', + 'orderby' => 'ID', + 'order' => 'ASC', + 'show_count' => 0, + 'hide_empty' => 0, + 'child_of' => 0, + 'exclude' => '', + 'echo' => 1, + 'selected' => 1, + 'hierarchical' => 1, + 'name' => $name, + 'id' => $id, + 'class' => 'form-no-clear', + 'depth' => 0, + 'tab_index' => 0, + 'taxonomy' => $taxonomy, + 'hide_if_empty' => true + ); ?> + + +
+
+ $term->name, 'url' => get_term_link($term), ); +} + +function udesly_get_taxonomies($taxonomy, $limit = 0, $post_id = null) +{ + if (!$post_id) { + global $post; + $post_id = $post->ID; // loop post + } + + $taxonomy = $taxonomy != '' ? $taxonomy : 'cat'; + + $tax_ids = wp_get_post_terms($post_id, $taxonomy, array( + 'number' => $limit + )); + + // Return categories + $taxonomies = array(); + + foreach ($tax_ids as $tax) { + $taxonomies[] = (object)array('name' => $tax->name, 'link' => get_term_link($tax)); + } + + return $taxonomies; } \ No newline at end of file diff --git a/udesly-adapter-plugin.php b/udesly-adapter-plugin.php index 472e4b2..6954a9d 100644 --- a/udesly-adapter-plugin.php +++ b/udesly-adapter-plugin.php @@ -11,7 +11,7 @@ * Plugin Name: Udesly Adapter * Plugin URI: https://www.udesly.com * Description: This is a support plugin for Udesly (Webflow to WordPress converter) that allows you to enable additional features for your theme. - * Version: 2.0.2 + * Version: 2.0.3 * Author: Udesly * Author URI: https://www.udesly.com * License: GPL-2.0+ @@ -29,7 +29,7 @@ // Constants defined('UDESLY_ADAPTER_PLUGIN_DIRECTORY_PATH') ?: define('UDESLY_ADAPTER_PLUGIN_DIRECTORY_PATH', plugin_dir_path(__FILE__)); defined('UDESLY_ADAPTER_PLUGIN_DIRECTORY_URL') ?: define('UDESLY_ADAPTER_PLUGIN_DIRECTORY_URL', plugin_dir_url(__FILE__)); -defined('UDESLY_ADAPTER_VERSION') ?: define('UDESLY_ADAPTER_VERSION', "2.0.2"); +defined('UDESLY_ADAPTER_VERSION') ?: define('UDESLY_ADAPTER_VERSION', "2.0.3"); defined('UDESLY_TEXT_DOMAIN') ?: define('UDESLY_TEXT_DOMAIN', "udesly-adapter-plugin"); defined('UDESLY_ADAPTER_PLUGIN_MISC_PATH') ?: define('UDESLY_ADAPTER_PLUGIN_MISC_PATH', plugin_dir_path(__FILE__) . 'includes/misc/');