You really have two major flaws in your code:
-
query_posts
needs to go before your loop, not inside it -
Never use
query_posts
in the first place unless you need to break something on your page
To learn why not to use query_posts
and when to use a custom query and how to use it, check this post I have done a while ago
So, in order to correct your code in your template, we are going to make use of WP_Query
and not query_posts
, and we are going to do the query before the loop
Try something like this:
<?php
/* Template Name: song Page
*
* Selectable from a dropdown menu on the edit page screen.
*/
?>
<?php get_header(); ?>
<div>
<?php
$args = array(
'post_type' => 'song'
);
$q = new WP_Query($args);
if ( $q->have_posts() ) {
while ( $q->have_posts() ) {
$q->the_post();
//Add your template tags like below
the_title();
} // end while
wp_reset_postdata();
} // end if
?>
</div>
Also, never forget to reset custom queries if you have used the loop or setup_postdata($post)
with wp_reset_postdata()