The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Custom WordPress Loop Question…

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #35773

    Ok… I’ve got a slider plugin that creates a custom post type and each image is a post in that post type. It has a shortcode generator that is used to help a user copy/paste the shortcode into the page where they want to feature it. I love this little gallery, easily customizable and easy to use… except the shortcode generator part. So what I’d like to do since I’m doing this on the home page only anyway is be able to grab the ids of the posts and create the shortcode bit by hand.

    The shortcode is formatted like this:
    [galaxy_slider slide=”60,59,58″ animation=”fade”]

    So I’m trying to figure out how to loop through all posts in the GalaxySlide post type and grab their id’s and then put them together in the slide=”60,59,58′ part.

    Can anyone point me in the right direction…?


    Ok… answered my own question… lol… I love how sometimes, writing out the problem in a forum post triggers the answer in my brain. For anyone else that wants to figure out how to do this:

    $args = array( 'post_type' => 'galaxy_slider' );
    $loop = new WP_Query( $args );
    $shortcode = '[galaxy_slider slide="';
    while ( $loop->have_posts() ) : $loop->the_post();
    $slideIDs = $slideIDs . $post->ID . ',';
    $slideIDs = substr($slideIDs, 0, -1);
    $shortcode = $shortcode . $slideIDs . '" animation="horizontal-push" speed="600" width="650" height="350"]';

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Other’ is closed to new topics and replies.