Post type attachment from specific user

I have without any luck been trying hardcoding to refer your slideshow plugin to show attachments submitted to a post. Below is what I have been experimenting with but nothing shows but "No slides are available". Your support is much appreciated.

$pid = $post->ID;
$uid = $user->ID;

$args = array(
'order' => 'ASC',
'post_type' => 'attachment',
'post_parent' => $pid,
'post_author' => $uid,
'meta_key' => 'image',
'meta_value' => '1',
'numberposts' => -1,
'post_status' => null,
);
$attachments = get_posts($args);

echo '<div class="slideshow">';
if (function_exists('slideshow')) { slideshow($output = true, $gallery_id = false, $post_id = $attachments, $params = array()); }
echo '</div>';

Comments

  • 3 Comments sorted by
  • Vote Up0Vote Down
    @nikwin

    Thank you for your question.

    Please take a look at the Slideshow plugin online documentation at the following link:

    https://tribulant.com/docs/wordpress-slideshow-gallery/9532/shortcodes-hardcodes-for-displaying-a-slideshow/

    There are some shortcodes and hard-coding examples that you might find useful.

  • Vote Up0Vote Down
    @nevena

    Thank you for your reply. I am quite new to digging into the code of wordpress and have been trying to make sense of the examples in the online documentation.

    Am I then correct to assume that it will be a problem referencing the slideshow to $attachments since it is an array? Or is it possible to somehow provide multiple posts (in my case posts of the attachment type) to the slideshow plugin?
  • Vote Up0Vote Down
    @nikwin

    Yes it is a problem to pass the $attachments array as the $post_id, it won't work. That parameter specifically takes a $post_id numeric/integer value.

    So that is currently the only way you can do it.
  • Vote Up0Vote Down
    edited March 2019
    @tribulant

    Thanks for the info. A shot in the dark since I consider myself a beginner, but could a possible workaround be to assemble my attachments to a gallery which is then used for the slideshow? Something similar to below?
    function assemble_gallery() {

    $images = get_children(array(
    'post_parent' => $pid,
    'post_author' => $uid,
    'post_type' => 'attachment',
    'numberposts' => -1,
    'post_mime_type' => 'image',
    )
    );

    if($images) {
    $gallery = '<ul class="gallery">';
    foreach( $images as $image ) {
    $gallery .= '<li>';
    $gallery .= '<a href="' . wp_get_attachment_url($image->ID) . '" rel="shadowbox">';
    $gallery .= wp_get_attachment_image($image->ID);
    $gallery .= '</a>';
    $gallery .= '</li>';
    }
    $gallery .= '</ul>';

    return $gallery;
    }

    }

    echo '<div class="slideshow">';
    if (function_exists('slideshow')) { slideshow($output = true, $gallery_id = $gallery, $post_id = false, $params = array()); }
    echo '</div>';
Sign In or Register to comment.