[wp-hackers] Need help with query_posts and custom post types

Jason Grim jgrim at jgwebdevelopment.com
Fri Apr 29 09:52:56 UTC 2011


Thanks Jonathan,

Nacin suggested I try using parse_request or wp_query->set(). Which seemed
to work perfectly.

Sincerely,
Jason Grim
jgrim at jgwebdevelopment.com
Owner / Lead Developer
JG Web Development
"a new standard for web design"
(937) 557-1477
www.JGWebDevelopment.com



On Thu, Apr 28, 2011 at 3:13 AM, Jonathon Byrd <jon at 5twentystudios.com>wrote:

> you should try running this without using the query_posts as this function
> is global and is a custom-ed to remembering prior queries. If you REALLY
> want to use it this way, then run wp_reset_query() to clear the query_vars
> prior.
>
> I suggest that you do this instead.
>
> $args = array (
> 'post_type' => 'iphone_apps',
> 'year' => '2011',
> 'monthnum' => '4',
> 'day' => '13',
> 'posts_per_page' => '5',
> 'cat' => '5'
> );
>
> $apps = new WP_Query;
> $apps->query( $args );
> global $post;
>
> if ( $apps->have_posts() ) { while ( $apps->have_posts() ) {
> $apps->the_post();
> //now you can use $post as normal
>
> }}
>
> Sincerely,
>
> Jonathon Byrd | Partner | Senior Software Engineer
> 5 Twenty Studios, LLC
>
> C: (360) 747-7401 | O: (503) 268-1177 | F: (954) 867-1177
> jon at 5twentystudios.com | www.5TwentyStudios.com<
> http://www.5twentystudios.com/>
>
>
>
> On Wed, Apr 27, 2011 at 9:24 PM, Jason Grim <jgrim at jgwebdevelopment.com
> >wrote:
>
> > This is my first post to wp-hackers.
> > Trying to use query_posts() to create a custom page through a custom
> > rewrite
> > with the following arguments:
> >
> > $args = array (
> >
> > 'post_type' => 'iphone_apps',
> > 'year' => '2011',
> > 'monthnum' => '4',
> > 'day' => '13',
> > 'posts_per_page' => '5',
> > 'cat' => '5'
> >
> > );
> >
> > It's creating the following sql query:
> >
> > > SELECT SQL_CALC_FOUND_ROWS wp_posts.*
> > > FROM wp_posts
> > > INNER JOIN wp_term_relationships
> > > ON (wp_posts.ID = wp_term_relationships.object_id)
> > > WHERE 1=1
> > > AND YEAR(wp_posts.post_date)='2011'
> > > AND MONTH(wp_posts.post_date)='4'
> > > AND DAYOFMONTH(wp_posts.post_date)='13'
> > > AND ( wp_term_relationships.term_taxonomy_id IN (5) )
> > > AND wp_posts.post_type IN ('post', 'articles', 'nav_menu_item',
> > > 'iphone_apps', 'ipad_apps', 'mac_apps')
> > > AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 1 AND
> > > wp_posts.post_status = 'private')
> > > GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 5
> >
> >
> > Seems to be including all post types rather than the one inserted?
> >
> > Purpose of doing this: the plugin I'm creating for a site is to
> > run independent of the theme. Trying to avoid the creation of empty
> pages.
> >
> > Any advice?
> >
> > Sincerely,
> > Jason Grim
> > jgrim at jgwebdevelopment.com
> > Owner / Lead Developer
> > JG Web Development
> > "a new standard for web design"
> > (937) 557-1477
> > www.JGWebDevelopment.com
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list