[wp-hackers] get_posts with both a custom post_type and custom taxonomy
Christopher O'Connell
jwriteclub at gmail.com
Tue Oct 13 00:52:29 UTC 2009
I agree, it should respect post type. Although, I've been solving this
with pure SQL.
YMMV
~ Christopher
Sent from my iPhone
On Oct 12, 2009, at 16:27, Leo germani <leogermani at gmail.com> wrote:
> Hi Aaron,
>
> I often have the same problem when I want a custom query. Thing is
> some
> arguments overwrite the others in this function, and your resulting
> query is
> selecting posts with post type = post.
>
> My workaround is to use the query_posts hook to strip out this
> condition
> from the resulting sql whenever I want.
>
> This is an area where Im not sure wether its a bug or an expected
> behavior.
> But I think if you pass the post_type paramater it should respect it
> no
> matter what other paramaters are passed... Any one agree we could
> open a
> ticket for that? To not let other paramaters overwrite the post_type
> paramater?
>
> Leo,,
>
> On Mon, Oct 12, 2009 at 5:35 PM, Aaron Jorbin
> <aaron.jorbin at gmail.com>wrote:
>
>> I'm having an issue with get_posts and using a custom post_type and
>> custom taxonomy. It seems to always return empty. If I do
>> `
>> $args = array('post_type' => 'my_post_type', 'foo' => 'bar');
>> $my_posts = get_posts ($args);
>> `
>> foo is registered as a registered taxonomy that has query_var set
>> to true.
>> If I do a custom query for the following, it returns exactly what I
>> would expect.
>>
>> `
>> $sql = "SELECT * from $wpdb->posts
>> LEFT JOIN $wpdb->term_relationships ON
>> $wpdb->term_relationships.object_id = $wpdb->posts.id
>> WHERE `$wpdb->posts`.`post_type` = 'my_post_type'
>> AND `$wpdb->term_relationships`.`term_taxonomy_id` =
>> $my_term_id
>> ";
>>
>> `
>>
>> Is there an additional step that I am missing? I opened up a trac
>> ticket at http://core.trac.wordpress.org/ticket/10934 but haven't
>> heard any responses there, so perhaps this isn't an actual bug. Any
>> help that you can lead would be greatly appreciated.
>>
>> -Aaron Jorbin
>>
>> --
>> aaron.jorbin at gmail.com
>> http://aaron.jorb.in
>> Twitter: @aaronjorbin
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
>
>
> --
> leogermani.pirex.com.br
> leogermani.estudiolivre.org
> _______________________________________________
> 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