Home › Forum › Problemi Vari con WP › Interfacciarsi al database WP
-
AutorePost
-
-
27 Febbraio 2018 alle 11:55 #31669SpartacusPartecipante
Buongiorno,
confido proprio nel vostro aiuto.
Avrei la necessità di assegnare ad una variabile (nel file functions.php) un valore che è presente nel DB di WP.
Ho individuato dove è presente il valore nel DB (tabella e campo) ma non so come assegnare il valore che mi interessa alla variabile.
Potreste darmi un aiuto?
Ho letto la vs guida a questo indirizzo http://www.wpitaly.it/wiki/Main/ClasseWPDB ma non riesco ad estrarre il valore.
Nel DB ho qualcosa di simile:
option_id | option_name | option_value | autoload
236 | upper_options | a:14:{…;s:19:”service_description”;s:681:”Qui è presente il valore della stringa che mi interessa prelevare“;s:17:”service_one_title”;s:13:”Lavoro”;s:16:”service_one_icon”;s:9:”fa-laptop”;s:32:”service_one_description”;s:921:”Qui è presente una seconda descrizione che successivamente dovrò assegnare ad una seconda variabile”;s:61:”service_two_icon”;s:50:”fa-th”;s:71:”service_two_title”;s:11:”Strumenti”;s:32:”service_two_description”;s:51:”Qui è presente una terza descrizione che successivamente dovrò assegnare ad una terza variabile”;…;} | yes
A me occorre assegnare alla variabile il valore relativo alla “service_description” (che nel caso che ho indicato come esempio sarebbe il testo: Qui è presente il valore della stringa che mi interessa prelevare)
Grazie a chi mi darà una mano.
-
27 Febbraio 2018 alle 14:21 #122070SteveAglAmministratore del forum
Niente di esoterico e nemmeno usare la classe WPDB quelal option la leggi con https://developer.wordpress.org/reference/functions/get_option/
Essendo ua gruppo di valori serializzati il risultato sarà un array associativo che quindi avrai a disposizione tutti i valore contenuti
-
27 Febbraio 2018 alle 14:47 #122071SpartacusPartecipante
Grazie per il tuo suggerimento.
Essendo io un neofita di WP e PHP,
potresti dirmi come posso fare per accedere proprio a quel determinato valore dell’array?
N.B.: considerando che devo assegnare questo valore ad una stringa nel file “functions.php”
Te ne sarei veramente grato.
Ci sto sbattendo la testa da 1 settimana
-
1 Marzo 2018 alle 7:18 #122076SteveAglAmministratore del forum
sarà una cosa del genere
$pippo = get_option( ‘upper_options’ , 1);
$pippo conterrà il valore che ti server per vedere tutto l’array e capire lasua struttura puoi banalpemte fare:
echo print_r( $pippo, 1 );
Direi che però se non si hanno le basi PHP minime di programmazione e non si riesce a leggere il codex (ho postato il link) pasticciare col codice mi pare una cattiva idea, sopratutto se il progetto è pubblico e professionale. DI solito non forniamo codice preconfezionato, perchè se poi non va si torna qua a chiedere etc etc, le basi PHP sono fondamentali per questo genere di richieste
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.