Ottenere gli URL di immagini in una galleria?
-
16-10-2019 - |
Domanda
Ho bisogno di recuperare gli URL per le immagini all'interno di una galleria, che cosa è la query SQL appropriato per questo, in base all'ID post?
Al momento ho qualcosa come il seguente che ho trovato su via google , ma non so come accedere alla variabile WP globale dall'esterno Wordpress - cosa devo fare?
function getGallery($id)
{
global $wpdb;
//SQL query to retrieve all attachment of mime type image/jpeg from the given post
$querystr = "
SELECT ID, post_name, guid, meta_value
FROM $wpdb->posts wposts
INNER JOIN $wpdb->postmeta meta ON meta.post_id = wposts.ID AND meta.meta_key = '_wp_attachment_metadata'
WHERE wposts.post_type = 'attachment'
AND wposts.post_parent = '".$id."'
AND wposts.post_mime_type = 'image/jpeg'
";
//get result set from the query
$pictures = $wpdb->get_results($querystr, ARRAY_A);
//return resultset
return $pictures;
}
Soluzione
Credo che la funzione è wp_get_attachment_url (). C'è anche uno per le miniature. Vedi wp-includes / media.php.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange