Home › Forum › Problemi Vari con WP › Come assegno una categoria ad un post?
-
AutorePost
-
-
18 Giugno 2010 alle 9:54 #14195DigItalWarriorPartecipante
Ciao ragazzi anche se leggo da moltissimo tempo questo forum e mi è sempre stato di enorme aiuto, adesso è giunto anche per me il momento di chiedere aiuto ed allora ecco il mio primo post.
Sto facendo uno scriptino che in base alle dimensioni delle immagini presenti in un articolo dovrebbe assegnare la categoria “immagini”. La mia domanda è: come posso fare ad assegnare la categoria “immagini” al post che ha i criteri richiesti dallo script?.
Lo script è già fatto, a me serve solo una mano su come fare ad assegnare la categoria al post in questione.
Grazie
-
18 Giugno 2010 alle 11:33 #74304SteveAglAmministratore del forum
Puoi filtrare la lista delle categorie di un articolo prima che vengano salvate intercettando il filtro:
http://adambrown.info/p/wp_hooks/hook/%7B$field_no_prefix%7D_save_pre
per la parte riguardante le categorie, alla lista separata da virgole potrai aggiungere la tua categoria (ora dovrei vedere nel codice se vuole il nome o l’abbreviazione normalizzata o l’ID)
-
18 Giugno 2010 alle 13:35 #74313DigItalWarriorPartecipante
Cia Steve, grazie per la risposta.
Sinceramente cercavo qualcosa di più semplice da applicare a livello del file funcctions.php.
In pratica, assumendo che un post sia già assegnato ad una o più categorie, volevo fare una cosa semplice tipo:
if ($dimension == ‘X’) {
query che assegna la categoria.
}
Un query semplicissima che dovrebbe assegnare anche la categoria “immagini” lasciando le altre già presenti.
Il problema è che non riesco a raccapezzarmi perché anche analizzando il db non capisco quali sono i criteri che legano posts/categorie/tags.
Al limite se c’è un link dove posso andare a leggere su come funzionano i “legami” detti poc’anzi mi va benissimo lo stesso.
Grazie
-
18 Giugno 2010 alle 15:43 #74327SteveAglAmministratore del forum
Ma va fatto esattamente nella function aggancio quell’hook al filtro.. altri modi non ci sono anche perchè la tua funzione di analisi deve analizzare l’articolo nel momento in cui viene salvato verificare se deve mettere la categoria, verificare non sia già stata assegnata (salvataggi successivi al primo) e nel caso aggiungerla alle categorie selezionate per quell’articolo, questo è il solo modo per farlo…
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.