Making WordPress.org

Changeset 10704


Ignore:
Timestamp:
02/18/2021 05:54:14 AM (5 years ago)
Author:
dd32
Message:

Support Forums: User Badges: Switch out wp_get_post_terms() for get_the_terms() which is an older preferred variant of the function with caching.

Removes a query per user per thread.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-user-badges/inc/class-plugin.php

    r10672 r10704  
    131131
    132132        foreach ( $types as $type ) {
    133             $slugs = wp_get_post_terms( $topic_id, 'topic-' . $type, array( 'fields' => 'slugs' ) );
    134             if ( $slugs ) {
     133            $terms = get_the_terms( $topic_id, 'topic-' . $type );
     134            if ( $terms ) {
    135135                break;
    136136            }
    137137        }
    138138
    139         if ( ! $slugs || is_wp_error( $slugs ) ) {
     139        if ( ! $terms || is_wp_error( $terms ) ) {
    140140            return false;
    141141        }
     
    143143        return array(
    144144            'type'          => $type,
    145             'slug'          => $slugs[0],
     145            'slug'          => $terms[0]->slug,
    146146            'user_nicename' => $user->user_nicename,
    147147        );
Note: See TracChangeset for help on using the changeset viewer.