Hello
I’m making a shortcode, I have a problem in my code but I don’t know what it’s wrong.
function categorie_shortcode_callback() {
$html = '';
$categories = get_categories( array(
'taxonomy' => 'carte-category',
'parent' => 0
));
shuffle( $categories);
if ( ! empty($categories) ) {
$category = $categories[0];
$html.= '<h3> '. $category->name. '</h3>';
$html.= '<p class="txtContent"> '. $category->description. '</p>';
$random_posts = get_posts( array(
'post_type' => 'carte',
'posts_per_page' => 1,
'orderby' => 'rand',
'fields' => 'ids',
'tax_query' => array(
array( 'taxonomy' => 'carte-category', 'terms' => $category->term_id, 'field' => 'term_id', 'category__not_in' =>[ 8, 9, 10] )
)
) );
if ( ! empty($random_posts) ) {
$html.='<h4>'.get_the_title( $random_posts[0]).'</h4>';
if ($category->term_id = 5){
while ( have_rows('formule', $random_posts[0]) ) : the_row();
while ( have_rows('tarif', $random_posts[0]) ) : the_row();
$html.= '<span class="type">'.get_sub_field('type', $random_posts[0]).'</span>';
$html.= '<span class="prix">'.get_sub_field('tarif', $random_posts[0]).' € </span>';
endwhile;
break;
endwhile;
$html .= get_the_post_thumbnail( $random_posts[0]);
} else{
$produits = get_field('produits', $random_posts[0]);
foreach($produits as $produit){
$nom = $produit['nom_du_produit'];
$html.= '<span class="type">'.$nom.'</span>';
}
}
}
}
return $html;
}
add_shortcode( 'categorie', 'categorie_shortcode_callback' );
the part after “else” is not working, my fields name are good and the content exists.
Someone knows how to resolve it ?