matpakka
Forum Replies Created
-
Thanks for your suggestions!
I have decided to try out a simple solution to this issue, because there does not seem to be a easy way to fix this.I now only want to disable the parent for being selected, so that the businesses unfortunately have to pick every single country. (That way at least the countries selected will be correct.)
To make this work I am trying to use some jQuery, that is supposed to target the multi-select dropdown.
jQuery( document ).ready(function($) { var titles= ["Africa", "Asia", "Europe"]; $(".select2-search__field").click(function(){ for(var i=0;i<=titles.length;i++){ $("ul li[title="+titles[i]+"]").removeAttr("aria-selected"); $("ul li[title="+titles[i]+"]").attr("aria-disabled","true"); } }) });It seems like the
ul liis rendered after the multi-select dropdown is clicked, that why I have tried to implement this code using.click.I also figured that the whole aria-selected attribute must be removed, while
aria-disabledshould be added withfalse.Still, there is something that prevents this code from working on my WP site. Even though this logic works here.
So once again, do you happen to have any suggestions on how to make this work?
- This reply was modified 5 years, 8 months ago by matpakka.
Hi!
I have made a custom multi-select field, using
<optgroup>to organize the continents:{optgroup}Africa|Uganda,Zambia,Zimbabwe{/optgroup}, {optgroup}Asia|Afghanistan,Bahrain,Bangladesh{/optgroup}This solves the problem on the front-end using the suggested Advanced Search addon. (Because customers most likely will not have to select continents)
I suppose the name of the continents act as group labels, while the countries are group values.
So to the big question: is there a way for businesses, using admin-backend and the “add/edit listing” page, to be able to select ALL the different Countries where they will ship their goods to – using the multi-select input field?
(Ex. If the wanna ship to Africa, they don’t have to choose all African countries – Only click Africa and all the other ones are selected)I know
Cntl + Clickis an option, but this not possible from mobile (?) and is not very intuitiveHello!
I haven’t made any further progress on this issue.
The changes are never visible at the front-end (either pre – or post save/update).
The changes I am referring to is seen for a brief moment in the log file I am using to trace the custom functions, before the changes are overwritten.
It seems like “something” is happening and preventing the changes from sticking to the
post_categoryfield in the DB table. (Some kind of function/action taking place after the my_post_filter function that overwrites thepost_categoryfield?)Do you know what this “something” might be?
- This reply was modified 5 years, 9 months ago by matpakka.
Hello!
Thanks for your answer and example code! We actually had a similar discussion regarding the exact same issue three months ago.
My end goal is to use GeoDirectory to create a subscription listing site. On this site businesses can list their deals, while customers can browse through the different businesses and deals using various sorting filters.
A main sorting option should be “Ship To”, where customers should be able to select all businesses that will ship to a particular customers Country.
On the admin-backend and the “add/edit listing” page, businesses should be able to select ALL the different Countries where they will ship their goods to – using the multi-select input field.
(I cannot see how the “Location Manager” could solve this issue, please correct me if I am wrong!)
Because of the potential high number of Countries, a business owner should be able to only select Continents (ex. Africa) if they ship goods to ALL Countries within this Continent. If however, one or more of the Countries in a Continent are un-checked or not selected, the continent itself will be un-checked/not selected.
To make this possible I have created a CPT and been trying to use the CPT category like this (Continents = Parents, Countries = children):
* Africa - Uganda - Zambia - Zimbabwe * Asia - Afghanistan - Bahrain - Bangladesh - BhutanBy implementing the code below, I seem to be able to achieve this Continent-Country behavior in the core WordPress taxonomy when selecting Continents or de-selecting Countries [Se Image]:
function array_diff_once($a1, $a2){ for each($a2 as $val){ if(false !== ($pos = array_search($val, $a1))){ unset($a1[$pos]); } } return array_values($a1); } add_action('set_object_terms', 'toggle_child_terms', 10, 6); function toggle_child_terms(object_id, terms, $tt_ids, taxonomy, append, $old_tt_ids){ // Abort if this is an autosave/backup if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; // Abort if no ids are set from before or now if(empty($tt_ids) && empty($old_tt_ids)) return; // Only do things if this post is published (front facing) $post_status = get_post_status(object_id); if($post_status != 'publish') return; // What terms where ADDED, and which were REMOVED? $added_terms = array_diff_once($tt_ids, $old_tt_ids); removed_terms = array_diff_once($old_tt_ids, $tt_ids); // Any terms ADDED this time? If(!empty($added_terms)){ for each($added_terms as $added_term){ // Do any of these added terms have children? If($added_child_terms = get_term_children($added_term, taxonomy) ){ // Append those children wp_set_object_terms(object_id, $added_child_terms, taxonomy, true); } } } // Any terms REMOVED? If(!empty(removed_terms)){ for each(removed_terms as removed_term){ // Do any of the removed terms have children? If(removed_child_terms = get_term_children(removed_term, taxonomy) ){ // Remove them all wp_remove_object_terms(object_id, removed_child_terms, taxonomy, true); } } } }But these changes are NOT visible inside the CPT subscription post [See img]
When looking at the
wp_geodir_gd_subscription_detailtable in the database, there is a field calledpost_categorythat are populated with values from the category input field (Ship To) – See image above. When looking more closely, I can tell that the values in the ‘post_category’ field are NOT the same as:categories = wp_get_post_terms($gd_post['post_ID'], 'gd_subscriptioncategory', array('fields' => 'ids') );For making ‘post_category’ match the core WordPress category settings (Continent – country) that are generated through the custom toggle_child_terms function (above), I have been trying to somehow copy the content from
categories = wp_get_post_terms($gd_post['post_ID'], 'gd_subscriptioncategory', array('fields' => 'ids') );to ‘post_category’ in different ways, unfortunately without success.
add_filter('geodir_save_post_temp_data','my_post_filter',15,3); function my_post_filter($gd_post, $post, update){ categories = wp_get_post_terms($gd_post['post_ID'], 'gd_subscriptioncategory', array('fields' => 'ids') ); $gd_post['post_category'] = categories; custom_logs($gd_post['post_category']); custom_logs($gd_post); return $gd_post; }For this last try, using your example code, I seem to be able to copy the categories at first, custom_logs output:
{---"post_category":[626,627,628,629,630,631,632,633,634,625,635,636,637],"---},but then when the page is refreshed only the selected in Continent was checked and not the Countries – the same for the
post_categoryfield in the database.It seems like “something” happens after the
geodir_save_post_temp_datahook that reverts thepost_categoryfield back to pre-my_post_filter categories.I hope this explanation made sense, and that you might have an advice for me that could lead to a solution for this issue.
Thank you!
- This reply was modified 5 years, 9 months ago by matpakka.
There is something I am not getting with this
geodir_save_post_temp_datafilter. With this code below, I am only updating thepost_categorywith the previous values.add_filter('geodir_save_post_temp_data','_my_post_cat_stuff',10,3); function _my_post_cat_stuff( $gd_post, $post, $update){ global $gd_post; $categories = get_the_terms( $gd_post->ID, 'gd_placecategory' ); $term_id = array(); if($categories) { foreach( $categories as $term ) { $term_id[] = $term->term_id; } } $output = implode(",",$term_id); custom_logs("CATEGORY OUTPUT"); custom_logs($output); // set some new cats by id $gd_post['post_category'] = $output; // specifically set the default cat (sometimes used in the URL) (optional) $gd_post['default_category'] = $output[0]; return $gd_post; }Is there a way I could pass arguments from my custom
set_object_termshook to thegeodir_save_post_temp_datafilter?- This reply was modified 6 years ago by matpakka.
Thanks for your answer, not entirely sure how to customize this
geodir_save_post_temp_datafilter to update thepost_categoryfield?Forum: Plugins
In reply to: [WP Job Manager] set Category parent as optgroup if it has children.UPDATE
I managed to fix this problem by replacing the plugin core file class-wp-job-manager-category-walker.php with<?php /** * File containing the class My_WP_Job_Manager_Category_Walker. * * @package wp-job-manager */ if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Walks through categories. * * @extends Walker * @package wp-job-manager * @since 1.0.0 */ class My_WP_Job_Manager_Category_Walker extends WP_Job_Manager_Category_Walker { /** * Tree type that the class handles. * * @var string */ public $tree_type = 'category'; /** * Database fields to use. * * @var array */ public $db_fields = [ 'parent' => 'parent', 'id' => 'term_id', 'slug' => 'slug', ]; function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { $pad = str_repeat(' ', $depth * 3); $cat_name = apply_filters('list_cats', $category->name, $category); if ('list' == $args['has_children'] && $args['taxonomy'] == 'job_listing_category'){ // $this->optgroup = true; $output .= "<optgroup class=\"level-$depth\" label=\"".$cat_name."\" >"; } else { $output .= "<option class=\"level-$depth\" value=\"".$category->term_id."\""; if ( $category->term_id == $args['selected'] ) $output .= ' selected="selected"'; $output .= '>'; $output .= $pad.$cat_name; if ( $args['show_count'] ) $output .= ' ('. $category->count .')'; $output .= "</option>"; } } function end_el(&$output,$object,$depth) { if ('list' == $args['has_children'] && $args['taxonomy'] == 'job_listing_category') { $output .= '</optgroup>'; } } }The problem I now face is the fact that this can be overwritten whenever the WP job admin plugin will be updated!
Therefor I tried to follow this suggestion in order to fix this problem, so far none of the suggestions seems to work. I might have the wrong filter.
function wp_job_manager_optgroup_parent_category( $args ){ // include new walker class - where ever you saved/named it //include_once( 'wp-job-manager/class-wp-job-manager-categroy-walker.php' ); // set the name as the new walker for the widget args $args['walker'] = new My_WP_Job_Manager_Category_Walker; return $args; } add_filter( 'job_manager_job_filters_search_jobs_start', 'wp_job_manager_optgroup_parent_category' );have also tried the following filters:
- job_manager_job_filters_search_jobs_start
- job_manager_job_filters_before
- job_manager_term_multiselect_field_args
- job_manager_dropdown_categories
Any suggestions on how to fix this?
Forum: Plugins
In reply to: [WP Job Manager] set Category parent as optgroup if it has children.Thank you for the suggestion, I did try the WP Job Manager Field Editor add-on.
It has no option for setting parent category as <optgroup>Forum: Plugins
In reply to: [Maps Builder - Google Maps Plugin] Map in tab, click functionI manage to fix this my self.
Forum: Plugins
In reply to: [Maps Builder - Google Maps Plugin] Map in tab, click functionForum: Plugins
In reply to: [Maps Builder - Google Maps Plugin] Map in tab, click functionThe page is in maintenance mode, but I can send you the url and login credentials somewhere?