0

I'm facing a strange problem:

  <?php $loop = new WP_Query( array( 'post_type' => 'ff', 'orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => 10 ) );
              while ( $loop->have_posts() ) : $loop->the_post(); ?>

(...)

              <?php endwhile; ?> 

This code displays all posts of "ff" type. Works fine.

But I do not want to list all posts of this type, I just want the ones that are in "ff_show" category (so the slug/term is "ff_show).

Codex tells me that I should use 'category_name' but when I do the loop is always empty:

  <?php $loop = new WP_Query( array( 'post_type' => 'ff', 'category_name' => 'ff_show',  'orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => 10 ) );

I've tried typing everything after 'category_name', nothing works.

The funny thing is when I use category instead of category_name - it ALWAYS shows all the posts. No matter what ID I give.

Am I doing something wrong?

I'm sure about my category name, it is exactly as I said.

When I login to my panel admin and go to categories and hover over one of them it points to:

http://localhost/wordpress/wp-admin/edit-tags.php?action=edit&taxonomy=frontpage_categories&post_type=ff&tag_ID=19

BUT 'cat' => '19' shows nothing.

:/

  • What makes you think the cat parameter would work on the edit-tags page? Why does it need to? – t31os Dec 18 '10 at 20:45
1

Are you absolutely sure ff_show is correct slug? I have suspicions about that underscore...

category is not valid query argument at all, it is probably simply discarded.

Had you tried this query with id instead of slug? cat argument.

Edit.

Wait, you are trying to query custom taxonomy? Category arguments have no relation to it at all.

Try frontpage_categories => ff_show (quick guess, don't remember specifics of querying custom stuff. again - not my area).

Yeah, found it at last Custom Taxonomies > Querying by Taxonomy

  • Updated. Nothing :( Anyways - is my code valid and should work? If it is then I'll search somewhere else... – Wordpressor Dec 18 '10 at 20:20
  • I am not sure about how post_type interacts with stuff (custom posts are not my area really), but I can't spot anything out of order with code so far. Can you simply query for category without rest of arguments? – Rarst Dec 18 '10 at 20:24
  • new WP_Query( array( 'post_type' => 'ff', 'category_name' => 'ff_show' ) ); - gives no results. I'm really 100% it's named that way because I'm just looking at category tables ;/ – Wordpressor Dec 18 '10 at 20:29
  • try changing category_name to category. custom post types should take the taxonomy term name as argument – onetrickpony Dec 18 '10 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.