How can I replace the values in WP_Term?

To replace values in a WP_Term object, you can modify its properties directly. For example: $term = get_term( $term_id, $taxonomy ); if ( ! empty( $term ) && ! is_wp_error( $term ) ) { $term->name=”New Term Name”; $term->slug = ‘new-term-slug’; $term->description = ‘New Term Description’; } In this example, the get_term() function is used to … Read more

How to get tags only with custom meta field and display them randomly?

You can get custom fields randomly using the below code that you can combine with your existing code to get desired output. function wpll_get_popular_nodes() { global $wpdb; $custom_fields = $wpdb->get_results( “select DISTINCT meta_value from $wpdb->postmeta pt LEFT JOIN $wpdb->posts p ON (pt.post_id = p.ID) where meta_key LIKE ‘tax_image_url_universal’ ORDER BY RAND()” ); if ( is_array( … Read more

How can I filter get_terms with post meta

If you want to output a list of terms that are assigned to the posts in the current query, you could use something like this in your template: global $wp_query; $terms = []; foreach ( $wp_query->get_posts() as $item ) { $item_terms = wp_get_post_terms( $item->ID, ‘web_cat’ ); $terms[] = $item_terms; } $unique = array_unique( array_merge(…$terms), SORT_REGULAR … Read more

How to solve/debug get_terms suddenly showing no results?

Prior to 4.5.0, the first parameter of get_terms() was a taxonomy or list of taxonomies: Since 4.5.0, taxonomies should be passed via the taxonomy argument in the $args array: So, the lines /** * Get the family */ $args = array( ‘parent’ => $topmost->term_id, ); $family = get_terms($taxonomy_name, $args); should be /** * Get the … Read more

Relate term to term?

Wow, it just works… I can use wp_set_object_terms() to set a term to a term… $term_taxonomy_ids = wp_set_object_terms( $bill_term_id, $microsoft_term_id, ‘company’ ); And I can retrieve the company connected to a person with wp_get_object_terms like… $bills_company_terms = wp_get_object_terms($bill_term_id, ‘company’); The only thing is, how can I put a backend interface on these relationships?

list taxonomy terms in current post / current category

You can try this: /** * List the taxonomies and terms for a given post * * @param int $post_id * @return string */ function get_the_current_tax_terms_wpse( $post_id ) { // get taxonomies for the current post type $taxonomies = get_object_taxonomies( get_post_type( $post_id ) ); $html = “”; foreach ( (array) $taxonomies as $taxonomy) { // … Read more