Support » Fixing WordPress » get_posts and foreach

  • Andrew


    I’m using get_posts to display attachments of my posts:

    $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID );
    $attachments = get_posts($args);
    if ($attachments) {
    foreach ( $attachments as $attachment ) {
    echo apply_filters( 'the_title' , $attachment->post_title );
    the_attachment_link( $attachment->ID , false );

    How can I change the code to exclude the echo so I can simply write out the HTML for the attachments?

Viewing 1 replies (of 1 total)
  • Andrew


    Okay, to elaborate a little bit more on my question, I’d like to get the attachment uri to use in a shortcode in my template.

    So how can I just get the attachment uri for use in a formatted link like so:

    [Shortcode src="wp_get_attachment_url"]

    based on the code in the previous post? Preferably without having to use PHP but HTML instead.

    The code is pulling the post’s attachments but how can I format the display of the attachments?

    Please help.

    Thank you,


Viewing 1 replies (of 1 total)
  • The topic ‘get_posts and foreach’ is closed to new replies.