logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$20
custom taxonomy template page issues

Warning: (lol)
If you have not worked with custom post-types in wp, alongside custom taxonomies, don't bother with this question. You will end up going in circles for days like I have.

Situation:
I have a custom post-type 'photogalleries' which I have also created 2 custom taxonomies for it, 'gallerycategories, gallery-tags'.

gallerycategories is heirarchical, while gallery-tags is not.

Post-type and taxonomies are registered and working perfectly. Both single and archive pages work for the photogalleries post-type.


Problem:
When I click on a taxonomy in my photogallery page, it takes me to a page showing all the photogalleries. IT SHOULD only show photogallery posts that belong to that taxonomy.

example single gallery:
http://shawn.theanointedone.com/photogallery/amazing-pet-pictures/

Right below the gallery title is the 'gallerycategories' taxonomy, in this case it is pets.

I created a custom template for gallerycategories which generates this page:
http://shawn.theanointedone.com/gallerycategories/pets/

The problem is all photogalleries are showing up, and not just 'pets'.


Problem 2:
Same thing happens for my gallery-tags.

The only difference is this time I did not create a template for tags, as there is no point, as I don't know what code to put in the template to make it work anyhow, should be same code as the first one anyhow.



Here is the code from my taxonomy-gallerycategories.php file
http://pastebin.com/1Y7dyMy1

Here is the code that generates the links to the gallerycategories terms on the single.php page:
<?php echo get_the_term_list( $post->ID, 'gallerycategories', '', ', ', '-' ); ?>


What I need:

I need the function to place into taxonomy-gallerycategories.php that is going to properly filter the displayed articles to only show the photogallery articles that belong to the 'gallerycategories' taxonomy term --determined via the url of course.


I'm guessing this problem is pretty easy to solve, but with no documentation yet, it's a serous pain in my butt.

This question has been answered.

shawn | 11/10/10 at 1:35am Edit

Previous versions of this question: 11/10/10 at 1:56am

(3) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    11/10/10
    1:53am
    Monster Coder says:

    Hello,
    I am also not 100% confident with this. Recently I am trying to understand it! My answers are more for my understanding rather than helping you ;)!

    First, when you created the link for Pets, did you create the link using

    get_term_link($term, $taxonomy)


    I have another question, let me do the homework first :P.

    • 11/10/10 1:55am

      shawn says:

      <?php echo get_the_term_list( $post->ID, 'gallerycategories', '', ', ', '-' ); ?>


    • 11/10/10 2:02am

      Monster Coder says:

      Ok, that seems ok too! As only one showing, I thought you hard coded it :P! I am updating soon, if I find something to share!

  • avatar
    Last edited:
    11/10/10
    3:32am
    Michael Fields says:

    Shawn, I don't believe that your template needs the following two lines:

    <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
    <?php query_posts(array( 'post_type'=>'photogallery', 'location'=>$term->slug)); ?>


    WordPress will automatically display terms for the queried (via url) taxonomy + term.

    The use of query_posts() to restrict post_type is not necessary. In my experience, it is best only to use query_posts() as a last resort or in special cases. IMO this is not one of them.

    Here is what one of the queries generate by wp() looks like on my test blog:

    SELECT SQL_CALC_FOUND_ROWS  wp_posts.*
    FROM wp_posts
    WHERE 1=1
    AND wp_posts.ID IN (546, 547)
    AND wp_posts.post_type IN ('post', 'page', 'attachment', 'piece')
    AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 1
    AND wp_posts.post_status = 'private')
    ORDER BY wp_posts.post_date DESC
    LIMIT 0, 3


    My custom taxonomy is "piece" and you can see that it is included in the query automatically.

    Removing the 2 aforementioned lines fixed the template for me.

    Previous versions of this answer: 11/10/10 at 2:06am

    • 11/10/10 2:10am

      shawn says:

      When I remove those 2 lines, which I just did again, I always get 'Sorry, no posts matched your criteria.'

      I believe this is because the query is searching 'posts' and not my custom post-type, but that is only my best guess.

      It's when I am combining custom post-type and custom taxonomies together to search via term, that I run into issues. Believe me... I've read every article I can find on this, and none seems to quite get there.

      **If it helps, you are the one person who I fully trust to give full access to the site to if it makes it easier**

    • 11/10/10 2:14am

      Michael Fields says:

      I can take a look if you would like me to. It is possible that this is a Woo specific issue. Before we get there, could you post the code that you used to create the taxonomy + post type. Through debugging various custom post_type related things I have realized that sometimes the error lies there and not so much in the template files.

    • 11/10/10 2:17am

      shawn says:

      http://pastebin.com/E4X2S4Rh

      I use this class because it is the best out there for allowing addition of the post-type archive pages rewrites until 3.1 comes out. Without that, I have found no way to activate the arhive files for the post-type.

      When I dig into the db, the post-type is indeed created properly, but then again you can see that from the function itself, which btw is pretty cool

    • 11/10/10 3:05am

      Michael Fields says:

      Shawn,

      You should remove this line from your post type declaration in functions.php:

      'exclude_from_search' => 'false',


      If I were you, I would remove most of the args that you have declared only setting those that need to be set.

      Then you should be able to remove the 2 lines from your template.

    • 11/10/10 3:18am

      shawn says:

      U DA MAN!

      Figured out that I only needed to take out the query line.

      I have to leave the other line in to have the ability to display the term name in my page. When I remove the $term = line then there is nothing defined for my query.

      I do have one last question if you don't mind, -- you win either way...

      I have the following line in my template, that is intended to show the description of the term on the page:

       Description:<?php echo term_description( '', get_query_var( 'gallerycategories' ) ); ?>


      This is not returning the description for my term, but it seems that it should.

      What query would you use?

      **$term is defined because you can now see on the top of the page:
      http://shawn.theanointedone.com/gallerycategories/pets/

      Photogalleries in Category: Pets ****It knows that we're on the pets term page.

    • 11/10/10 3:25am

      Michael Fields says:

      Sweet, glad it worked!

      Since you're in a term archive, the following is the easiest solution:

      term_description( get_query_var( 'term' ), get_query_var( 'taxonomy' ) );


      Will probably not work in other templates.

    • 11/10/10 3:31am

      shawn says:

      Yeah, didn't work. Tried with both echo and without.. will keep digging.

      <?php echo term_description( get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>


      Setting this response as the winner now.

      thanks so much yet again.

      This theme project is finally coming to a close and I think it looks pretty good. If I have further questions, I'll keep coming back here to post. This site and members totally rock.

  • avatar
    Last edited:
    11/10/10
    2:36am
    idt says:

    Hi Shawn,

    Have you seen this post by Justin Tadlock here: http://justintadlock.com/archives/2009/06/04/using-custom-taxonomies-to-create-a-movie-database

    idt

    Previous versions of this answer: 11/10/10 at 2:35am | 11/10/10 at 2:36am | 11/10/10 at 2:36am

    • 11/10/10 2:38am

      shawn says:

      Yes, read that article when it first came out. He does not even attempt what I am after.

    • 11/10/10 3:02am

      idt says:

      I see. I thought that the part about "Displaying taxonomy terms in a page" was the same as what you're trying to do, no? I might have misunderstood what you're trying to do.

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.