How to show list of taxonomy terms associated with specific post?

I used following codes and it is working perfectly. <?php $terms = wp_get_post_terms($post->ID, ‘competition’); ?> <?php $count = count($terms); if ( $count > 0 ) { foreach( $terms as $term ) {?> <section class=”achievement-section clearfix”> <?php $counter = 0; ?> <div class=” league-and-season clearfix”> <div class=”honour-league-name”> <?php echo $term->name; ?> </div> <?php $team = get_post_meta( … Read more

Page listing all categories for CPT

I would create a page in the admin panel called service areas and create a rewrite rule that tells wp to load a corresponding page-service-areas.php template. function add_rewrite_rules () { add_rewrite_rule( ‘^service_areas/?$’, ‘index.php?pagename=service-areas’, ‘top’ ); } add_action(‘init’, ‘add_rewrite_rules’); Then in page-service-areas.php build out the query you want. The following link helps you visualize how wordpress … Read more

Terms change id after importing

Off the top of my head, you’d have to either: (a) bypass the import functionality in WP and do it direct to the database, so the term IDs stay the same (i.e. export/import from phpMySQL). or (b) write a “run once” data migration function to update your term IDs once they’re imported, using a reference … Read more

Add attribute taxonomy through code don’t appear in admin product page

the solution is: foreach ($attributes as $attr => $value) { $attr=”pa_”.$attr; wp_set_object_terms($post_ID, $value, $attr); $thedata[sanitize_title($attr)] = Array( ‘name’ => wc_clean($attr), ‘value’ => $value, ‘postion’ => ‘0’, ‘is_visible’ => ‘1’, ‘is_variation’ => ‘1’, ‘is_taxonomy’ => ‘1’ ); } update_post_meta($post_ID, ‘_product_attributes’, $thedata);

Custom permalink accept any params

This is, I suppose, just how the query parser works. If you create a new WP_Query instance, and provide a post name, any taxonomy parameters you add will be ignored and will not be added to the query. Post uniqueness is determined entirely based on post slug, and uniqueness of slug is enforced. It’s possible … Read more

How to list the taxonomy terms that fit the custom query?

Get this recipe’s assigned terms (recipe having $recipe_id): $terms_arr = []; $terms_objs = get_the_terms($recipe_id, ‘main_ingredient’); if ($terms_objs) { foreach ($terms_objs as $term_obj) { $terms_arr[] = $term_obj->slug; } } Find the terms found in both arrays: $the_ingrediens = array_intersect($ingredients, $terms_arr);