WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Loop through multiple custom taxonomy terms and display posts for a custom post (3 posts)

  1. Thomas
    Member
    Posted 1 year ago #

    I am working with custom post types in the bones theme from themble. There, I want to create a link list and therefor i've created a custom post type, called links.

    This custom post type has a custom taxonomy, called links_categories. Now I would like to display all links on one page, like this:

    Link Category 1

    * Post 1
    * Post 2
    * ...

    Link Category 2

    * Post 1
    * Post 2
    * ...

    While researching on how to achieve this dynamically, i tried this two solutions:

    http://wordpress.stackexchange.com/questions/346/loop-through-custom-taxonomies-and-display-posts

    http://wordpress.stackexchange.com/questions/32447/custom-post-type-multiple-loop-by-taxonomy-term?rq=1

    Strangely enough I had the same issue with both versions. It seems like WP_Query is not getting any posts - I just get the slug of the custom category term.

    Here is what I have for now:

    http://pastebin.com/wAeN0tAp

    Any help on this would be really appreciated - i was working on this the whole afternoon...

  2. IMICreation
    Member
    Posted 1 year ago #

    change this
    $posts = new WP_Query( array(
    'taxonomy' => $taxonomy,
    'term' => $term->slug,
    'posts_per_page' => '-1'
    with
    $posts = new WP_Query( array(
    'links_categories' => $term->slug,
    'posts_per_page' => '-1'

  3. Thomas
    Member
    Posted 1 year ago #

    Thank you for your help!

    I had to add the post_type to the query - and with that additional line to your suggestion it works. Just for sake of completeness here is the working code:

    $posts = new WP_Query( array(
    'post_type' => $post_type,
    'links_categories' => $term->slug,
    'posts_per_page' => '-1'));

Topic Closed

This topic has been closed to new replies.

About this Topic