Comment obtenir des données de la base de données WordPress à l'aide de la requête WordPress $ wpdb?
-
-
J'ai vérifié ànouveauet j'aitrouvé que c'étaitmonproblème de codageet après avoir corrigé cela,le supérieurfonctionne également.Vouspouvez également utiliser la réponse ci-dessous ...I checked again and found that it was my coding problem and after fixing that, the upper one is also working. You can also use the below answer one too...
- 0
- 2014-09-29
- Muhammad Hassan
-
@ialocin Ok.Terminé...@ialocin Ok. Done...
- 0
- 2014-10-02
- Muhammad Hassan
-
2 réponses
- votes
-
- 2014-09-27
Justepour clarifier laméthode
get_var()
de$wpdb
fonctionnetrèsbien dans ce contexte:global $wpdb; $helloworld_id = $wpdb->get_var("SELECT ID FROM wp_posts WHERE post_name = 'hello-world'"); echo $helloworld_id;
Enfait,c'estpluspratique dans ce contexte,car une seule variableest renvoyée,ce quiest réellement souhaité.
Just to clarify the
get_var()
method of$wpdb
does work just fine in this context:global $wpdb; $helloworld_id = $wpdb->get_var("SELECT ID FROM wp_posts WHERE post_name = 'hello-world'"); echo $helloworld_id;
Actually it is more practical in this context, because a single variable is returned, which is what is actually wanted.
-
Merci dem'avoir confirmé quej'avaispartagé lebon codemais leproblème était dansmes autres codes,donc ça vamaintenant ...Thanks for confirming me that I shared the right code but the problem was in my other codes so its ok now...
- 0
- 2014-10-02
- Muhammad Hassan
-
- 2014-09-27
global $wpdb; $findID = $wpdb->get_results("SELECT ID FROM wp_posts WHERE post_name = 'hello-world'"); echo $findID[0]->ID;
I found the solution and the correct query to fetch one data from WordPress database is below one.
global $wpdb; $findID = $wpdb->get_results("SELECT ID FROM wp_posts WHERE post_name = 'hello-world'"); echo $findID[0]->ID;
-
Jene saispas quel était/est leproblème dans votre configuration,mais utiliser `get_var` devraitfonctionner correctement.Ilne devraitpas êtrenécessaire d'utiliser `get_results`,ce qui dans ce scénarioesten outre unpeupeupratique.Don't know what the problem in your setup was/is but using `get_var` should work just fine. There shouldn't be the need to use `get_results`, which in this scenario is additionally a bit impractical.
- 0
- 2014-09-27
- Nicolai
-
J'ai vérifié ànouveauet j'aitrouvé que c'étaitmonproblème de codageet après avoir résolu cela,la question 1fonctionne égalementtrèsbien.I checked again and found that it was my coding problem and after fixing that, the question one is also working fine.
- 0
- 2014-10-02
- Muhammad Hassan
J'essaye d'obtenir des données destables debase de données WordPress dans unplugin.Pour cela,j'utilise le code ci-dessous ...
Mais celane me donnepas l'identifiant depublication dans
echo
?Y a-t-il quelque chose quine vapas ...???