par
chaosad2 » 12 août 2024, 19:49
Bonjour,
Sur un site wordpress, je souhaite remplir un champ personnalisé en fonction de la valeur d'un autre.
J'ai des catégories de randonnées, et selon la catégorie (récupérée dans la variable $categorie_parcours), je veux modifier l'icone rattachée, en attribuant à la variable $marker le contenu des variables listées.
exemple : si $caegorie_parcours est égal à VTT, le champ marker prendra la valeur $marker_vtt.
J'ai tenté ce code :
Code : Tout sélectionner
<?php
$categorie_parcours = get_field('categorie');
$marker_pedestre = 'leaflet-extramarker markerColor=yellow iconColor=white shape=circle icon=fa prefix=fa-landmark';
$marker_vtt = 'leaflet-extramarker markerColor=green iconColor=white shape=circle icon=fa prefix=fa-landmark';
$marker_cyclo = 'leaflet-extramarker markerColor=blue iconColor=white shape=circle icon=fa prefix=fa-landmark';
$marker_gravel = 'leaflet-extramarker markerColor=brown iconColor=white shape=circle icon=fa prefix=fa-landmark';
$marker_trail = 'leaflet-extramarker markerColor=YellowGreen iconColor=white shape=circle icon=fa prefix=fa-landmark';
$marker_multisport = 'leaflet-extramarker markerColor=red iconColor=white shape=circle icon=fa prefix=fa-landmark';
if ($categorie_parcours = 'Multi-sports') {
update_field('marker',$marker_multisport);}
if ($categorie_parcours = 'Pédestre') {
update_field('marker',$marker_pedestre);}
if ($categorie_parcours = 'VTT') {
update_field('marker',$marker_vtt);}
if ($categorie_parcours = 'Cyclo') {
update_field('marker',$marker_cyclo);}
if ($categorie_parcours = 'Gravel') {
update_field('marker',$marker_gravel);}
if ($categorie_parcours = 'Trail') {
update_field('marker',$marker_trail);}
?>
Je n'ai pas d'erreur dans l'absolu, mais le champ prend systématiquement la dernière valeur (à savoir "trail" dans l'exemple).
Je suis débutant en php.
Où est mon erreur, ou où sont mes erreurs ?

Bonjour,
Sur un site wordpress, je souhaite remplir un champ personnalisé en fonction de la valeur d'un autre.
J'ai des catégories de randonnées, et selon la catégorie (récupérée dans la variable $categorie_parcours), je veux modifier l'icone rattachée, en attribuant à la variable $marker le contenu des variables listées.
exemple : si $caegorie_parcours est égal à VTT, le champ marker prendra la valeur $marker_vtt.
J'ai tenté ce code :
[code]
<?php
$categorie_parcours = get_field('categorie');
$marker_pedestre = 'leaflet-extramarker markerColor=yellow iconColor=white shape=circle icon=fa prefix=fa-landmark';
$marker_vtt = 'leaflet-extramarker markerColor=green iconColor=white shape=circle icon=fa prefix=fa-landmark';
$marker_cyclo = 'leaflet-extramarker markerColor=blue iconColor=white shape=circle icon=fa prefix=fa-landmark';
$marker_gravel = 'leaflet-extramarker markerColor=brown iconColor=white shape=circle icon=fa prefix=fa-landmark';
$marker_trail = 'leaflet-extramarker markerColor=YellowGreen iconColor=white shape=circle icon=fa prefix=fa-landmark';
$marker_multisport = 'leaflet-extramarker markerColor=red iconColor=white shape=circle icon=fa prefix=fa-landmark';
if ($categorie_parcours = 'Multi-sports') {
update_field('marker',$marker_multisport);}
if ($categorie_parcours = 'Pédestre') {
update_field('marker',$marker_pedestre);}
if ($categorie_parcours = 'VTT') {
update_field('marker',$marker_vtt);}
if ($categorie_parcours = 'Cyclo') {
update_field('marker',$marker_cyclo);}
if ($categorie_parcours = 'Gravel') {
update_field('marker',$marker_gravel);}
if ($categorie_parcours = 'Trail') {
update_field('marker',$marker_trail);}
?>
[/code]
Je n'ai pas d'erreur dans l'absolu, mais le champ prend systématiquement la dernière valeur (à savoir "trail" dans l'exemple).
Je suis débutant en php.
Où est mon erreur, ou où sont mes erreurs ? :)