I know that custom taxonomies are (currently) not a supported filter in the tagdiv page composer. Sadly for my client this function has become quite a turning point and a critical one that I really need to solve if I wish to deliver a working finished website.
So, following a couple of suggestions on here that it might be possible, I started looking into this, only to reach partial success.
As far as I know, this custom build will be overwritten with any new update so I know that if I get this working I need to reprogram this.
So, here’s what I got so far.
The filtering is defined in the td_config file, and I have based my trials upon the category function.
(basically copying it and adjusting it to what I thought/think should work)
I have copied and then altered this code:
array(
"param_name" => "category_id",
"type" => "dropdown",
"value" => td_util::get_category2id_array(),
"heading" => 'Category filter:',
"description" => "A single category filter. If you want to filter multiple categories, use the 'Multiple categories filter' and leave this to default",
"holder" => "div",
"class" => "tdc-dropdown-big",
'group' => $group
),
into this code
array(
"param_name" => "taxonomy_id",
"type" => "dropdown",
"value" => td_util::get_taxonomy2id_array(),
"heading" => 'ABC filter:',
"description" => "A single category filter. If you want to filter multiple categories, use the 'Multiple categories filter' and leave this to default",
"holder" => "div",
"class" => "tdc-dropdown-big",
'group' => $group
),
this breaks the website.
I keep seeing td_util::get_category2id_array so I am guessing (correct me if I am wrong) that this refers to the file found in wp booster folder “td_util.php”.
In that file I found indeed the get_category2id array arguments so I performed the same trick again.
Turning this code
/**
* generates a category tree, only on /wp_admin/, uses a buffer
* @param bool $add_all_category = if true ads - All categories - at the begining of the list (used for dropdowns)
* @return array
*/
private static $td_category2id_array_walker_buffer = array();
static function get_category2id_array($add_all_category = true) {
if (is_admin() === false) {
return array();
}
if (empty(self::$td_category2id_array_walker_buffer)) {
$categories = get_categories(array(
'hide_empty' => 0,
'number' => 1500
));
$td_category2id_array_walker = new td_category2id_array_walker;
$td_category2id_array_walker->walk($categories, 4);
self::$td_category2id_array_walker_buffer = $td_category2id_array_walker->td_array_buffer;
}
if ($add_all_category === true) {
$categories_buffer['- All categories -'] = '';
return array_merge(
$categories_buffer,
self::$td_category2id_array_walker_buffer
);
} else {
return self::$td_category2id_array_walker_buffer;
}
}
into this
/**
* generates a taxonomy tree, only on /wp_admin/, uses a buffer
* @param bool $add_all_taxonomy = if true ads - All taxonomies - at the begining of the list (used for dropdowns)
* @return array
*/
private static $td_taxonomy2id_array_walker_buffer = array();
static function get_taxonomy2id_array($add_all_taxonomy = true) {
if (is_admin() === false) {
return array();
}
if (empty(self::$td_taxonomy2id_array_walker_buffer)) {
$taxonomys = get_taxonomys(array(
'hide_empty' => 0,
'number' => 1500
));
$td_taxonomy2id_array_walker = new td_taxonomy2id_array_walker;
$td_taxonomy2id_array_walker->walk($taxonomies, 4);
self::$td_taxonomy2id_array_walker_buffer = $td_taxonomy2id_array_walker->td_array_buffer;
}
if ($add_all_taxonomy === true) {
$taxonomies_buffer['- All taxonomies -'] = '';
return array_merge(
$taxonomies_buffer,
self::$td_taxonomy2id_array_walker_buffer
);
} else {
return self::$td_taxonomy2id_array_walker_buffer;
}
}
and a bit further down this
class td_category2id_array_walker extends Walker {
var $tree_type = 'category';
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
var $td_array_buffer = array();
function start_lvl( &$output, $depth = 0, $args = array() ) {
}
function end_lvl( &$output, $depth = 0, $args = array() ) {
}
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
$this->td_array_buffer[str_repeat(' - ', $depth) . $category->name . ' - [ id: ' . $category->term_id . ' ]' ] = $category->term_id;
}
function end_el( &$output, $page, $depth = 0, $args = array() ) {
}
}
into this
class td_taxonomy2id_array_walker extends Walker {
var $tree_type = 'taxonomy';
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
var $td_array_buffer = array();
function start_lvl( &$output, $depth = 0, $args = array() ) {
}
function end_lvl( &$output, $depth = 0, $args = array() ) {
}
function start_el( &$output, $taxonomy, $depth = 0, $args = array(), $id = 0 ) {
$this->td_array_buffer[str_repeat(' - ', $depth) . $taxonomy->name . ' - [ id: ' . $taxonomy->term_id . ' ]' ] = $taxonomy->term_id;
}
function end_el( &$output, $page, $depth = 0, $args = array() ) {
}
}
Alas to no avail.
I know you guys don’t support the taxonomies in the tagdiv (why I don’t know) and that you simply dont have time to do this kind of custom builds, but could you help me out on this one.
What am I doing wrong or is this really the complete wrong way to try to achieve what I want ?
once again, the custom taxonomy that I have made is called “alphabetical letter”.
Hi,
Taxonomy and custom post type support is quite limited in the theme as it stands. There are some modifications mentioned in these topics if you would like to try and modify the theme files, but they might not work anymore
– https://forum.tagdiv.com/topic/filter-blocks-by-custom-taxonomies/
– https://forum.tagdiv.com/topic/custom-taxonomy-or-custom-query-for-newspaper-blocks/
– https://forum.tagdiv.com/topic/how-to-add-taxonomy-filter-in-block-filter-settings/
no, none of them work anymore.
I can get the extra field to show in the tagdiv composer but that’s it really.
I looked into the option of the first link but wouldn’t know where to alter in the tdblock.php
