Boa tarde @everaldomatias,
consegui resolver do jeito que queri, irei postar a resolução a baixo:
function prefix_register_featured_taxonomy_marcas() {
$labels = array(
‘name’ => esc_html__( ‘Lista Marcas’, ‘text-domain’ ),
‘singular_name’ => esc_html__( ‘Lista Marcas’, ‘text-domain’ ),
‘all_items’ => esc_html__( ‘Todas as Marcas’, ‘text-domain’ ),
);
$args = array(
‘label’ => esc_html__( ‘Lista Marcas’, ‘text-domain’ ),
‘labels’ => apply_filters( ‘prefix_featured_taxonomy_labels’, $labels ),
‘public’ => false,
‘hierarchical’ => true,
‘show_ui’ => true,
‘show_in_rest’ => true,
‘show_in_menu’ => true,
‘show_in_nav_menus’ => true,
‘query_var’ => true,
‘rewrite’ => true,
‘show_admin_column’ => true,
‘show_in_quick_edit’ => true,
‘sort’ => true,
‘capabilities’ => array(
‘manage_terms’ => true,
‘edit_terms’ => true,
‘delete_terms’ => true,
),
);
register_taxonomy( ‘list_marcas’, array( ‘product’ ), apply_filters( ‘prefix_featured_taxonomy_args’, $args ) );
}
add_action( ‘init’, ‘prefix_register_featured_taxonomy_marcas’, 10 );
function prefix_add_featured_terms() {
global $wpdb;
$taxonomies= $wpdb->get_results(“SELECT DISTINCT
$wpdb->posts.ID,
$wpdb->posts.post_date,
$wpdb->posts.post_title,
$wpdb->posts.post_name,
$wpdb->terms.name Taxonomy,
$wpdb->terms.slug
FROM $wpdb->posts
INNER JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
INNER JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
INNER JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
INNER JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
WHERE $wpdb->posts.post_status = ‘publish’
and $wpdb->posts.post_type = ‘product’
and $wpdb->terms.name = ‘Chevrolet’
ORDER BY $wpdb->terms.name and $wpdb->posts.ID ASC
“);
$featured_terms = null;
foreach ( $taxonomies as $taxonomie) {
$featured_terms [$taxonomie->post_name] = esc_html__( $taxonomie->post_title, ‘text-domain’ );
}
foreach ( apply_filters( ‘prefix_featured_terms’, $featured_terms ) as $term => $name ) {
if ( ! term_exists( $name, ‘list_marcas’ ) ) {
wp_insert_term(
$name, ‘list_marcas’, $args = array(
‘slug’ => $term,
)
);
}
}
update_option( ‘prefix_featured_terms_added’, true );
}
add_action( ‘init’, ‘prefix_add_featured_terms’, 20 );
-
Esta resposta foi modificada 6 anos, 10 meses atrás por
joaocarloszen.