How to dynamically attach pictures to a carousel

I am trying to make single pages for each individual portfolio piece. I created custom posts & field types, but it only seems to allow one featured picture per post. Should I be adding my pictures in a different way? Or is there an option to add more featured images?

Also, I am trying to make a carousel with these images. I want the final result to carousel through different images of the individual portfolio piece. I am trying to write this argument with a new WP_Query, but it doesn’t seem to be working. Here is my argument:

 <?php
        $args = array(
            'post_type' => 'attachment',
            category_name =>'single-portfolio'

            );
        $the_query = new WP_Query ($args);

       ?>
       <?php if (have_posts ()) : while ($the_query->have_posts()) : $the_query -> the_post(); ?>
<h1><?php the_title();?>

   <?php endwhile; endif;?>

This is not pulling in my featured images. What am I doing wrong? Are there better arguments to pass through?

My website is www.angelina-marie.com

Solutions Collecting From Web of "How to dynamically attach pictures to a carousel"

It’s an interesting task.
We can make a custom Slider Menu in Dashboard then featured images can be upload from there so that those images can be called dynamically in slider.

First we have to make Theme Support and register Post Type in functions.php

add_theme_support( 'post-thumbnails', array( 'post', 'slider' ) );
add_image_size( 'slider-image', 1024, 550, true );

function create_post_type() {
   register_post_type( 'slider', 
      array(
         'labels' => array(
                         'name' => __( 'Slides' ),
                         'singular_name' => __( 'Slide' ),
                         'add_new' => __( 'Add New' ),
                         'add_new_item' => __( 'Add New Slide' ),
                         'edit_item' => __( 'Edit Slide' ),
                         'new_item' => __( 'New Slide' ),
                         'view_item' => __( 'View Slide' ),
                         'not_found' => __( 'Sorry, we couldn\'t find the Slide you are looking for.' )
                     ),
          'public' => true,
          'publicly_queryable' => false,
          'exclude_from_search' => true,
          'menu_position' => 14,
          'has_archive' => false,
          'hierarchical' => false,
          'capability_type' => 'page',
          'rewrite' => array( 'slug' => 'Slide' ),
          'supports' => array( 'title', 'thumbnail' )
      )
    );
  }
add_action( 'init', 'create_post_type' );

Now, in the file where the slider images run, we need to make a loop and inside the loop demonstrate query to get the images from database as well as call the query result.

<?php
    if(!is_paged())
    {
        $args = array('post_type' => 'slider', 'posts_per_page' => 4);
        $the_query = new WP_Query( $args );
            if ( $the_query->have_posts() ) 
            {
                while ( $the_query->have_posts() ) 
                {
                    $the_query->the_post();
                    $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'slider-image' );             
?>

                    <div data-src="<?php echo $image; ?>"> </div> 

<?php               }
            }
    } 
?>

That’s it you’re done! Now images uploaded from your Slides menu will be shown in slider.

I don’t see that you’ve actually asked for your featured image in the template. Throw in a call to the_post_thumbnail() between the_post() and endwhile to see if you have any better luck.

You will nee to do what Justin suggested.
But also your query have many issues. You are also not checking if your custom query has posts. You should use query like this.

<?php

    $args = array(
        'post_type'      => 'attachment',
        'category_name'  => 'single-portfolio'
    );

    $the_query = new WP_Query ( $args );

    if ( $the_query->have_posts() ) :

        while ( $the_query->have_posts() ) : $the_query->the_post();

        ?>

            <h1><?php the_title(); ?></h1>
            <?php the_post_thumbnail(); ?>

        <?php

        endwhile;

    endif;

    wp_reset_postdata();

?>

Also, notice that if you are running a custom query then you can reset post data at the end with wp_reset_postdata()