Hey guys,
Would it be possible to add the ability to filter blocks by custom taxonomy? You should be able to filter by combination of category and custom taxonomy.
That’s a shame. Custom taxonomies are commonly used for categorising posts and its something we make heavy use of on our site.
What about the possibility of allowing the block query to be modified before the query is run? i.e. allow us to pass in values to parent::render($atts) which modify the query.
Right now we have an ugly hack in place where we run our own query right after the block query executes and then we use the result of our query to pass to the modules. But obviously this is very inefficient!
Hi,
A solution for this would be to manually set the parameters used by the render method – http://screencast.com/t/lZtb4rHl – or modify the method – http://screencast.com/t/cnYqozxlmk58
I’ve added your suggestion on our list, we’ll look for a method to add more flexibility to this area.
Thank you!
Hi Emil,
Thanks for your reply. We’ve looked at solution 1…manually setting the parameters used by the render method. But the problem is that the query is created in the td_data_source->shortcode_to_args() function which takes the $atts array and creates the query. That function does not support custom taxonomies.
And as far as we can tell, its not possible to override the td_block and td_data_source files in a child theme. It would be nice if we could pass in extra query filters via $atts which td_data_source->shortcode_to_args() would then add to the generated query.
OR allow us to override td_block and td_data_source 🙂
Hi,
It’s possible to extend those classes(td_block and td_data_source) and customize their methods (td_block::render and td_data_source->shortcode_to_args) you can look for a guide on web or check the official documentation – http://php.net/manual/en/keyword.extends.php
Use the ‘td_wp_booster_loaded’ hook – http://screencast.com/t/hbykR0wS
Look how the main files are called above the hook – http://screencast.com/t/vSDjTPiD4KK
Beside this you have to add custom new fields in the block settings panel, follow the path and modify the files which handles that area. It a complicated task, a simpler way would be to modify the theme code directly. If you still want to doit from the child theme and you don’t know how i suggest that you hire a professional developer to help you with this customization. You can find one on places like – http://studio.envato.com/
We plan to add more options in the future but i cannot provide details about it yet, we have a lot of features on the list and we have to take them one by one.
Thank you!
Thanks Emil!
I think that will work for us. I’ll try it tomorrow and let you know how I get on.
Basically I can replace the implementation of td_data_source with our own implementation in our child theme. Love it 🙂
add_action(‘td_wp_booster_loaded’, ‘hook_td_booster_loaded’);
function hook_td_booster_loaded(){
td_api_autoload::add(‘td_data_source’, CHILD_THEME . ‘/includes/wp-booster/td_data_source.php’);
}
Simply copying td_data_source.php into the child theme and modifying also works. This is the approach we are using, nice and simple!
Hey,
We were able to add config to each of the block settings (in visual composer) using a function hooked to admin_init. This allows the user to specify a list of terms in that taxonomy and filter the results by those terms.
function extendCustomTaxonomyOptions() {
// Check if Visual Composer is installed
if ( ! defined( 'WPB_VC_VERSION' ) ) {
return;
}
// Retrieve all Lifestyle taxonomy
$terms = get_terms('name_of_your_custom_taxonomy_here');
if( !is_wp_error( $terms ) && count( $terms ) > 0 ) {
$dropdown = array(
'Disabled' => 'disabled',
'All Custom Taxonomy Terms' => 'all'
);
foreach( $terms as $term ) {
$dropdown["- {$term->name}"] = $term->term_id;
}
// Param to be added
$new_param = array(
'type' => 'dropdown',
'heading' => 'Filter based on custom taxonomy',
'param_name' => 'adv_filtering_custom_taxonomy',
'group' => 'Filter',
'admin_label' => true,
'value' => $dropdown,
'description' => __( 'If selected, will further filter the posts based on the custom taxonomy', 'vc_extend' )
);
// Integrate and add new parameter to the options available from the parent theme
// See https://wpbakery.atlassian.net/wiki/pages/viewpage.action?pageId=524335 for more info
for ( $i = 1; $i <= 16; $i++) {
vc_add_param( "td_block_{$i}", $new_param);
}
vc_add_param( "td_block_slide", $new_param);
}
}
Then we added some custom code in a child theme copy of the td_data_source class to read those settings and filter the results. This was added to the end of the td_data_source::shortcode_to_args() function, just before returning the $wp_query_args:
if( array_key_exists( 'adv_filtering_custom_taxonomy', $atts ) ) {
if( $atts['adv_filtering_custom_taxonomy'] != 'disabled' && !empty( $atts['adv_filtering_custom_taxonomy'] ) ) {
// Add new taxonomy in the query
$query = array_merge( $wp_query_args, array(
'tax_query' => array(
array(
'taxonomy' => 'name_of_your_custom_taxonomy_here',
'field' => 'term_id',
'terms' => $atts['adv_filtering_custom_taxonomy']
)
)
));
}
}
Hope that helps!
This implementation has stopped working since upgrading to Newsmag 3.0
Any thought guys?
HI
Since V3 we made some major changes in block’s structure and all atts are now defined in td_block.php file. Maybe new implementation conflict with your code and it may be required an adjustment.
Unfortunately I can’t debug the code provided as this involve custom work and we can’t provide such services at the moment. If you still can’t manage to solve this issue my advice is to look for someone who can help you with implementation or hire a developer to update the code for you.
Thanks!
We also like to know if anyone has a solution for the latest theme version. I think maybe the developers should already add this feature to the theme.
yes, custom taxonomies should be added to the filter options of the blocks. I’ve been literally breaking my head on trying to come up with a solution for our alphabetical index…
