• I have created a custom post type called locations.

    I have one custom taxonomy called cities.

    There are 4 cities named portland, phoenix, tucson, and bullhead-city.

    Is there a way I can query these custom posts, and separate these custom posts into columns with their corresponding cities?

    Kinda new to query strings and custom posts. Thanks!

Viewing 1 replies (of 1 total)
  • wpismypuppet

    (@wordpressismypuppet)

    This isn’t tested, but it’s along the idea you are looking for…

    $post_type = 'locations';
    
    // Get all the taxonomies for this post type
    $taxonomies = get_object_taxonomies( (object) array( 'post_type' => $post_type ) );
    
    foreach( $taxonomies as $taxonomy ) : 
    
        // Gets every "category" (term) in this taxonomy to get the respective posts
        $terms = get_terms( $taxonomy->name );
    
        foreach( $terms as $term ) : 
    
            $posts = new WP_Query( array( 'taxonomy' => $taxonomy, 'term' => $term->slug, 'posts_per_page' => -1 ) );
    
            if( $posts->have_posts() : while( $posts->have_posts() ) : $posts->the_post();
                //Do you general query loop here
            endwhile; endif;
    
        endforeach;
    
    endforeach;
Viewing 1 replies (of 1 total)
  • The topic ‘Displaying and Separating Custom Posts by Taxonomy’ is closed to new replies.