[wp-hackers] CPT Loop Question - I am stumped!

Mike Walsh mpwalsh8 at gmail.com
Fri Oct 21 14:54:23 UTC 2011


I suspect this a "can't see the the forest through the trees" situation but
I've been looking at this off and on for a couple days and am not sure what
I am doing wrong.  I am working on a site for my daughter's soccer team and
have defined a custom post type for the roster called "player".  I can add
players and all of the information I've defined for each without any issue.
 However, when I want to display the information on a page (e.g. the roster
page), I am not getting what I expect and I am not sure why.  I've defined a
short code that can appear on a post or page that will do nothing more than
build a table that contains the roster - player names, jersey number,
position, etc.

My short code does this:

    // Query players from the database.
    $loop = new WP_Query(
        array(
            'post_type' => 'player',
            'order_by' => 'title',
            'order' => 'ASC',
            'posts_per_page' => -1,
        )
    ) ;
    var_dump($loop->query) ;

When I loop through the posts I notice a couple things:

   1. The custom posts are not ordered based on the title, they are ordered
   by post id.
   2. The query results include the post id for the page I have the short
   code embedded on (this one really stumps me).

I added another query argument ('post__not_in' => array(get_the_ID())) to
see if I could eliminate the page's post id but that didn't work either.  As
I noted above, I suspect I am doing something very basic incorrectly but I
can't see it so any guidance would be greatly appreciated.

Mike

-- 
Mike Walsh - mpwalsh8 at gmail.com


More information about the wp-hackers mailing list