Get_term_by only returns one item from array
try this.. $filter_terms = array(); foreach ($widget[‘select’] as $key => $name) { $filter_terms[$key] = get_term_by( ‘name’, $name, ‘portfolio-categories’); }
try this.. $filter_terms = array(); foreach ($widget[‘select’] as $key => $name) { $filter_terms[$key] = get_term_by( ‘name’, $name, ‘portfolio-categories’); }
wp_update_term does not support custom fields so you will need to use update_term_meta instead. This stores values like this: update_term_meta( $term_id, $metakey, $metavalue ); Your code should look something like this: update_term_meta( 41, ‘clpr_store_url’, $url); update_term_meta( 41, ‘clpr_store_aff_url’, $url);
You’d write a script to loop through a file you created with the data, and process each line one at a time. Inside the loop you’d have code like the following. You would, of course, replace my example values Scotland, Glasgow, its description and its slug with variables representing the data for the row being … Read more
If you don’t give the cookie an expires time it will only be available during that session. You will also need to destroy an existing cookie if it is already set. jQuery(function() { jQuery(‘#categoriesform’).submit(function(e) { if (jQuery.cookie(‘my_cookie’) ) { jQuery.cookie( ‘my_cookie’, null) } jQuery.cookie(‘my_cookie’, ‘my_value’, { expires: 30 }); }); }); Have you tested to … Read more
Version 4.4 saw the introduction of the register_taxonomy_args filter in register_taxonomy() which you can use to filter the arguments used to register a taxonomy /** * Filter the arguments for registering a taxonomy. * * @since 4.4.0 * * @param array $args Array of arguments for registering a taxonomy. * @param array $object_type Array of … Read more
Currently your code is modifying all term queries, both in the front-end and in the back-end. Each navigational menu is registered as a term in the nav_menu taxonomy, so when you visit the backend to work on the menus, those queries have been modified too by your code snippet. For example, I don’t see any … Read more
I think you’re looking for term_exists function. Example Code: <?php $term = term_exists(‘tag1’, ‘post_tag’); if ($term !== 0 && $term !== null) { echo “‘tag1’ post_tag exists!”; } else { echo “‘tag1’ post_tag does not exist!”; } ?>
My apologies. After some more searching, I found that I could pass the taxonomy as an argument in wp_list_categories. Here is the info via WordPress Codex.
I didn’t understood your question well, but try this. Explanation is in the comments. // your taxonomy name $tax = ‘post_tag’; // get the terms of taxonomy $terms = get_terms( $tax, [ ‘hide_empty’ => false, // do not hide empty terms ]); // loop through all terms foreach( $terms as $term ) { // if … Read more
I think you can just use get_terms() for this. This is just some bare minimum code, I guess you also want to add permalinks, term description or other things. However, I just tested this code (now tested with taxonomy “course”) and it works. I try my best to comment the code as we go along: … Read more