Skip to content

Instantly share code, notes, and snippets.

@igmoweb
Created September 25, 2019 09:15
Show Gist options
  • Select an option

  • Save igmoweb/d73f36c4a29c94823fa25aec2a6a1f23 to your computer and use it in GitHub Desktop.

Select an option

Save igmoweb/d73f36c4a29c94823fa25aec2a6a1f23 to your computer and use it in GitHub Desktop.
<?php
$tags = wp_get_object_terms( $post_id, 'product_tag' );
// array_filter sólo se queda con los elementos que devuelven true dentro de la función anónima.
// Lista de etiquetas cuyo padre es marcas (podría ser más de uno).
// 10 es el Term ID de Marcas
$tags_that_belong_to_marcas_term = array_filter( $tags, function ( $term ) {
return 10 === absint( $term->parent );
} );
if ( ! empty( $tags_that_belong_to_marcas_term ) ) {
$image = get_term_meta( $tags_that_belong_to_marcas_term[0], 'imagen_de_marca' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment