setting taxonomy term to bulk posts using ids

I hope I understand this correctly. You can simply just add your post ID’s in an array and then use a foreach loop to loop through the ID’s and checking whether or not they have the term to assign or not, and if not, assign the term to the post $post_ids = [4522, 4524, 4526, … Read more

get_terms orderby numeric

You can use usort to sort the object $children. The function to sort after you got the $children object can be like this: usort( $children, function($a, $b) { $ai = filter_var($a->name, FILTER_SANITIZE_NUMBER_INT); $bi = filter_var($b->name, FILTER_SANITIZE_NUMBER_INT); if ($ai == $bi) { return 0; } return ($ai < $bi) ? -1 : 1; });

Invalid argument supplied for foreach() in search.php

Because get_the_terms will not always return an array; it will be false if the post has no terms, or a WP_Error if the taxonomy does not exist – always sanity check the result before looping: $terms_slugs = array(); $terms = get_the_terms( $post->id, ‘type’, /* Note: get_the_terms does not take a 3rd argument ==> */ array( … Read more

get_term_by “name” not working with & in name

The characters <, >, &, ” and ‘ (less than, greater than, ampersand, double quote and single quote) are enconded in term names. & becomes &amp;. This is done by passing the term object to sanitize_term() function which applies several filters. By default WordPress applies theses filters: sanitize_text_field(), wp_filter_kses() and _wp_specialchars() (see wp-includes/default-filters.php), this last … Read more

how to filter each tag item?

On the top of my head there are two easy ways to go about this problem, first is to use the get_the_tags() function to manually loop the tags to easily insert the hashtags. $tags = get_the_tags(); if ( $tags ) { foreach ( $tags as $tag ) { ?> <a href=”https://wordpress.stackexchange.com/questions/225250/<?php echo get_tag_link( $tag->id ); … Read more