has_term example


function has_category( $category = '', $post = null ) {
    return has_term( $category, 'category', $post );
}

/** * Checks if the current post has any of given tags. * * The given tags are checked against the post's tags' term_ids, names and slugs. * Tags given as integers will only be checked against the post's tags' term_ids. * * If no tags are given, determines if post has any tags. * * For more information on this and similar theme functions, check out * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ * Conditional Tags} article in the Theme Developer Handbook. * * @since 2.6.0 * @since 2.7.0 Tags given as integers are only checked against * the post's tags' term_ids, not names or slugs. * @since 2.7.0 Can be used outside of the WordPress Loop if `$post` is provided. * * @param string|int|array $tag Optional. The tag name/term_id/slug, * or an array of them to check for. Default empty. * @param int|WP_Post $post Optional. Post to check. Defaults to the current post. * @return bool True if the current post has any of the given tags * (or any tag, if no tag specified). False otherwise. */

                    }
                }
            }
        } elseif ( is_single() && str_contains( $wp_rewrite->permalink_structure, '%category%' ) ) {
            $category_name = get_query_var( 'category_name' );

            if ( $category_name ) {
                $category = get_category_by_path( $category_name );

                if ( ! $category || is_wp_error( $category )
                    || ! has_term( $category->term_id, 'category', $wp_query->get_queried_object_id() )
                ) {
                    $redirect_url = get_permalink( $wp_query->get_queried_object_id() );
                    $redirect_obj = get_post( $wp_query->get_queried_object_id() );
                }
            }
        }

        // Post paging.         if ( is_singular() && get_query_var( 'page' ) ) {
            $page = get_query_var( 'page' );

            

function has_post_format( $format = array()$post = null ) {
    $prefixed = array();

    if ( $format ) {
        foreach ( (array) $format as $single ) {
            $prefixed[] = 'post-format-' . sanitize_key( $single );
        }
    }

    return has_term( $prefixed, 'post_format', $post );
}

/** * Assign a format to a post * * @since 3.1.0 * * @param int|object $post The post for which to assign a format. * @param string $format A format to assign. Use an empty string or array to remove all formats from the post. * @return array|WP_Error|false Array of affected term IDs on success. WP_Error on error. */
Home | Imprint | This part of the site doesn't use cookies.