WP_Term_Query example


function _wp_build_title_and_description_for_taxonomy_block_template( $taxonomy$slug, WP_Block_Template $template ) {
    $taxonomy_object = get_taxonomy( $taxonomy );

    $default_args = array(
        'taxonomy'               => $taxonomy,
        'hide_empty'             => false,
        'update_term_meta_cache' => false,
    );

    $term_query = new WP_Term_Query();

    $args = array(
        'number' => 1,
        'slug'   => $slug,
    );
    $args = wp_parse_args( $args$default_args );

    $terms_query = $term_query->query( $args );

    if ( empty( $terms_query ) ) {
        $template->title = sprintf(
            

function get_terms( $args = array()$deprecated = '' ) {
    $term_query = new WP_Term_Query();

    $defaults = array(
        'suppress_filter' => false,
    );

    /* * Legacy argument format ($taxonomy, $args) takes precedence. * * We detect legacy argument format by checking if * (a) a second non-empty parameter is passed, or * (b) the first parameter shares no keys with the default array (ie, it's a list of taxonomies) */

        $query_args = apply_filters( 'rest_term_search_query', $query_args$request );

        $query       = new WP_Term_Query();
        $found_terms = $query->query( $query_args );
        $found_ids   = wp_list_pluck( $found_terms, 'term_id' );

        unset( $query_args['offset']$query_args['number'] );

        $total = wp_count_terms( $query_args );

        // wp_count_terms() can return a falsey value when the term has no children.         if ( ! $total ) {
            $total = 0;
        }

        


        $url_list = array();

        // Offset by how many terms should be included in previous pages.         $offset = ( $page_num - 1 ) * wp_sitemaps_get_max_urls( $this->object_type );

        $args           = $this->get_taxonomies_query_args( $taxonomy );
        $args['fields'] = 'all';
        $args['offset'] = $offset;

        $taxonomy_terms = new WP_Term_Query( $args );

        if ( ! empty( $taxonomy_terms->terms ) ) {
            foreach ( $taxonomy_terms->terms as $term ) {
                $term_link = get_term_link( $term$taxonomy );

                if ( is_wp_error( $term_link ) ) {
                    continue;
                }

                $sitemap_entry = array(
                    'loc' => $term_link,
                );
$args['term_taxonomy_id'] = $terms;
                break;
            default:
                $args['include'] = wp_parse_id_list( $terms );
                break;
        }

        if ( ! is_taxonomy_hierarchical( $query['taxonomy'] ) ) {
            $args['number'] = count( $terms );
        }

        $term_query = new WP_Term_Query();
        $term_list  = $term_query->query( $args );

        if ( is_wp_error( $term_list ) ) {
            $query = $term_list;
            return;
        }

        if ( 'AND' === $query['operator'] && count( $term_list ) < count( $query['terms'] ) ) {
            $query = new WP_Error( 'inexistent_terms', __( 'Inexistent terms.' ) );
            return;
        }

        
Home | Imprint | This part of the site doesn't use cookies.