WordPress.org

Forums

Get the url of attachments from the database ? (3 posts)

  1. Osama Ahmed
    Member
    Posted 2 years ago #

    I used the following code to get the images posted in a post

    $current_id = get_the_ID();
    $rows = $wpdb->get_results("select guid from $wpdb->posts where post_parent = $current_id");
    
    foreach ($rows as $row) {
    
    ?>
    
    <a>guid; ?>" data-titan-lightbox="on" data-titan-group="<?php the_ID() ?>"  style="display: none"><img src="<?php echo $row->guid; ?>" alt="Caption" class="Thumbnail thumbnail " width="228" height="160"></a>
    
    <?php

    but this code give the images path with the folder containing the images

    How can i get only the image from this loop ?

  2. Jose Castaneda
    THEME COFFEE MONKEY
    Posted 2 years ago #

    Did you try using wp_get_attachment_url() inside of your loop?

    You can also try using: get_children()

  3. Osama Ahmed
    Member
    Posted 2 years ago #

    i got it i have to alter my sql statement to be like the following

    select guid from $wpdb->posts where post_parent = $current_id" AND post_type = 'attachment'

    thanks

Topic Closed

This topic has been closed to new replies.

About this Topic