Query posts from taxonomy
-
I have been pecking away at this for awhile now and feel like it should not be this difficult unless I am missing something quite obvious.
I have a post type of “our_properties” and a registered taxonomy of “properties_community”. When someone clicks on Communities they are presented with a page that lists all the communities which works fine. However when a user clicks on a community they are brought to a page where it shows ALL posts from ALL communities. Instead I would like it to inherit the behavior as if someone were to click on a Category archive, so it would only show the posts or “properties” associated with that community.
I am using 3 files. One is where I register the post type and taxonomy, I have another template that displays the single post type and an archive template that displays the communities and posts associated with each.
Here is how I have registered my tax in that file:
//taxonomies add_action( 'init', 'create_my_taxonomies', 0 ); function create_my_taxonomies() { register_taxonomy( 'properties_community', 'our_properties', array( 'labels' => array( 'name' => 'Property Community', 'add_new_item' => 'Add New Community', 'new_item_name' => "New Community" ), 'show_ui' => true, 'show_tagcloud' => false, 'hierarchical' => true ) ); }
Here is how I pull it into my custom archive template:
//This is the slimmed down version <?php $args = array( 'post_type' => 'our_properties', 'post_status' => 'publish', 'posts_per_page' => -1, //'orderby' => 'post_date', //'order' => 'ASC', ); // END $args $my_query = null; $my_query = new WP_Query($args); ?> <?php if ( $my_query->have_posts() ) : ?> <div id="archive-container"> <!-- Start the Loop --> <?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?> <a href="<?php the_permalink(); ?>">View Full Details</a> </div> </div> <?php endwhile; ?>
And I feel like it might help if I show you a sample link so here that is: https://hardisonbuilding.com/our-communities-new-home-builders-in-wilmington-north-carolina/
Now if you go to that page and click on “Tarin Woods” for example, the next page you get to lists all the posts from all communities instead of just the posts associated with Tarin Woods.
What am I doing wrong or how can I fix?
- The topic ‘Query posts from taxonomy’ is closed to new replies.