Title: custom loop from metadata
Last modified: November 1, 2016

---

# custom loop from metadata

 *  Resolved [scottiescotsman](https://wordpress.org/support/users/scottiescotsman/)
 * (@scottiescotsman)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/custom-loop-from-metadata/)
 * I want to be able to list my metadata [in a drop down menu] from a custom post
   type so that I can make a custom loop.
    For instance: if I wanted archive-movies
   to list dependent on release date or alphabetically or its duration.
 * Hope someone can help
    Steven

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [James](https://wordpress.org/support/users/volcommky/)
 * (@volcommky)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/custom-loop-from-metadata/#post-8382432)
 * You can retrieve meta data with the [get_metadata()](https://codex.wordpress.org/Function_Reference/get_metadata)
 * First 2 arguments are required, type and object_id
 * From there you should be able to retrieve all metadata and do with it as you 
   may
 *  Thread Starter [scottiescotsman](https://wordpress.org/support/users/scottiescotsman/)
 * (@scottiescotsman)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/custom-loop-from-metadata/#post-8382845)
 * yes I know that as I have it in archives-movies.php & single-movies.php
 *     ```
       <p class="align_Right">
   
           	<select name="movieList" id="movieList">
   
                   <option value="0">Select List Order...</option>
                   <option value="dateAscending">Date Ascending</option>
                   <option value="dateDescending">Date Descending</option>
                   <option value="alphaUp">Alpha Ascending</option>
                   <option value="alphaDown">Alpha Descending</option>
   
       		</select>
   
               <input class="btnSort" type="submit" value="Go" name="sort">
   
           </p>
   
       <?php 
   
           $nam = get_post_meta( get_the_ID(), "name", true );
           $rel = get_post_meta( get_the_ID(), "released", true );
          $rat = get_post_meta( get_the_ID(), "rating", true );
          $dur = get_post_meta( get_the_ID(), "duration", true );
          $gen = get_post_meta( get_the_ID(), "genre", true );
           $dir = get_post_meta( get_the_ID(), "director", true );
              $wri = get_post_meta( get_the_ID(), "writer", true );
             $sta = get_post_meta( get_the_ID(), "stars", true );
            $sto = get_post_meta( get_the_ID(), "storyline", true );
            ?>
   
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       ```
   
 * its how to link it into the loop I cant figure out.
 *  [James](https://wordpress.org/support/users/volcommky/)
 * (@volcommky)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/custom-loop-from-metadata/#post-8383617)
 * You would move your code into the loop, the loop changes the post and get_the_ID()
   result each go around.
 *  Thread Starter [scottiescotsman](https://wordpress.org/support/users/scottiescotsman/)
 * (@scottiescotsman)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/custom-loop-from-metadata/#post-8386594)
 * I have it working on my site but it lists it in order of when I added the movie,
   I want to change that to whatever option I choose.
 *  [James](https://wordpress.org/support/users/volcommky/)
 * (@volcommky)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/custom-loop-from-metadata/#post-8387645)
 * You can create a custom WP_Query() and order it however you would like: [WP_Query](https://codex.wordpress.org/Class_Reference/WP_Query)
 *  Thread Starter [scottiescotsman](https://wordpress.org/support/users/scottiescotsman/)
 * (@scottiescotsman)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/custom-loop-from-metadata/#post-8388501)
 * that’s what I want to know lol
 *     ```
       <select name="movieList" id="movieList">
   
                       <option value="0">Select List Order...</option>
                       <option value="dateAscending">Date Ascending</option>
                       <option value="dateDescending">Date Descending</option>
                       <option value="alphaUp">Alpha Ascending</option>
                       <option value="alphaDown">Alpha Descending</option>
   
                   </select>
   
                   <input class="btnSort" type="submit" value="Go" name="sort">
   
               </p>
   
           <?php 
   
       		$nam = get_post_meta( get_the_ID(), "name", true );
   
       		$query = new WP_Query( array( 'category_name' => ' $nam ' ) );
   
          		if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
   
       	?>
       ```
   
    -  This reply was modified 9 years, 5 months ago by [scottiescotsman](https://wordpress.org/support/users/scottiescotsman/).
 *  [James](https://wordpress.org/support/users/volcommky/)
 * (@volcommky)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/custom-loop-from-metadata/#post-8388558)
 * Did you follow the link to see an example?
 *  Thread Starter [scottiescotsman](https://wordpress.org/support/users/scottiescotsman/)
 * (@scottiescotsman)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/custom-loop-from-metadata/#post-8393078)
 * yes I have seen a few but I am new to wordpress and I have been struggling with
   the code.
 *  Thread Starter [scottiescotsman](https://wordpress.org/support/users/scottiescotsman/)
 * (@scottiescotsman)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/custom-loop-from-metadata/#post-8401936)
 * yoohoo anyone home ?

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘custom loop from metadata’ is closed to new replies.

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [post](https://wordpress.org/support/topic-tag/post/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 2 participants
 * Last reply from: [scottiescotsman](https://wordpress.org/support/users/scottiescotsman/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/custom-loop-from-metadata/#post-8401936)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
